From ceaf38c61e73e0e0dc57cce1590b7ef6963e77d6 Mon Sep 17 00:00:00 2001 From: natalie-todd Date: Fri, 3 Jan 2025 11:37:47 -0800 Subject: [PATCH] Add validation enforcing at least one valid arch or valid URL and SHA and update changelog --- CHANGELOG.md | 4 ++-- admin_terraform_version.go | 25 ++++++++++++++++----- admin_terraform_version_integration_test.go | 5 +++-- errors.go | 2 ++ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 279cc97a7..7aa40a053 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,8 @@ ## Enhancements * Add support for project level auto destroy settings @simonxmh [#1011](https://github.com/hashicorp/go-tfe/pull/1011) -* Add `Archs` field to `AdminTerraformVersionCreateOptions` by @natalie-todd [#1022](https://github.com/hashicorp/go-tfe/pull/1022) - +* Add BETA support for Linux arm64 agents, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users @natalie-todd [#1022](https://github.com/hashicorp/go-tfe/pull/1022) + # v1.71.0 ## Enhancements diff --git a/admin_terraform_version.go b/admin_terraform_version.go index 3ea396848..78d75ce14 100644 --- a/admin_terraform_version.go +++ b/admin_terraform_version.go @@ -14,6 +14,12 @@ import ( // Compile-time proof of interface implementation. var _ AdminTerraformVersions = (*adminTerraformVersions)(nil) +const ( + linux = "linux" + amd64 = "amd64" + arm64 = "arm64" +) + // AdminTerraformVersions describes all the admin terraform versions related methods that // the Terraform Enterprise API supports. // Note that admin terraform versions are only available in Terraform Enterprise. @@ -209,12 +215,19 @@ func (o AdminTerraformVersionCreateOptions) valid() error { if !validString(o.Version) { return ErrRequiredVersion } - if !validString(o.URL) { - return ErrRequiredURL + if !o.validArch() && (!validString(o.URL) || !validString(o.Sha)) { + return ErrRequiredArchOrURLAndSha } - if !validString(o.Sha) { - return ErrRequiredSha - } - return nil } + +func (o AdminTerraformVersionCreateOptions) validArch() bool { + var valid bool + for _, a := range o.Archs { + valid = validString(&a.URL) && validString(&a.Sha) && a.OS == linux && (a.Arch == amd64 || a.Arch == arm64) + if valid { + break + } + } + return valid +} diff --git a/admin_terraform_version_integration_test.go b/admin_terraform_version_integration_test.go index 252162a7b..85a9bec25 100644 --- a/admin_terraform_version_integration_test.go +++ b/admin_terraform_version_integration_test.go @@ -116,8 +116,8 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) { Archs: []*ToolVersionArchitecture{{ URL: "https://www.hashicorp.com", Sha: *sha, - OS: "linux", - Arch: "amd64", + OS: linux, + Arch: amd64, }}, } tfv, err := client.Admin.TerraformVersions.Create(ctx, opts) @@ -194,6 +194,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { Arch: "amd64", }}, } + tfv, err := client.Admin.TerraformVersions.Create(ctx, opts) require.NoError(t, err) id := tfv.ID diff --git a/errors.go b/errors.go index 935f5b361..fdb68e53f 100644 --- a/errors.go +++ b/errors.go @@ -274,6 +274,8 @@ var ( ErrRequiredURL = errors.New("url is required") + ErrRequiredArchOrURLAndSha = errors.New("valid arch or url and sha is required") + ErrRequiredAPIURL = errors.New("API URL is required") ErrRequiredHTTPURL = errors.New("HTTP URL is required")