diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c5d6f95d..7aa40a053 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ # Unreleased ## Enhancements -* Add support for project level auto destroy settings @simonxmh [#1011](https://github.com/hashicorp/go-tfe/pull/1011) +* Add support for project level auto destroy settings @simonxmh [#1011](https://github.com/hashicorp/go-tfe/pull/1011) +* 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 6ae0de9d9..78d75ce14 100644 --- a/admin_terraform_version.go +++ b/admin_terraform_version.go @@ -7,12 +7,19 @@ import ( "context" "fmt" "net/url" + "reflect" "time" ) // 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. @@ -55,6 +62,13 @@ type AdminTerraformVersion struct { CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` } +type ToolVersionArchitecture struct { + URL string `jsonapi:"attr,url"` + Sha string `jsonapi:"attr,sha"` + OS string `jsonapi:"attr,os"` + Arch string `jsonapi:"attr,arch"` +} + // AdminTerraformVersionsListOptions represents the options for listing // terraform versions. type AdminTerraformVersionsListOptions struct { @@ -70,15 +84,16 @@ type AdminTerraformVersionsListOptions struct { // AdminTerraformVersionCreateOptions for creating a terraform version. // https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/terraform-versions#request-body type AdminTerraformVersionCreateOptions struct { - Type string `jsonapi:"primary,terraform-versions"` - Version *string `jsonapi:"attr,version"` // Required - URL *string `jsonapi:"attr,url"` // Required - Sha *string `jsonapi:"attr,sha"` // Required - Official *bool `jsonapi:"attr,official,omitempty"` - Deprecated *bool `jsonapi:"attr,deprecated,omitempty"` - DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"` - Enabled *bool `jsonapi:"attr,enabled,omitempty"` - Beta *bool `jsonapi:"attr,beta,omitempty"` + Type string `jsonapi:"primary,terraform-versions"` + Version *string `jsonapi:"attr,version"` // Required + URL *string `jsonapi:"attr,url"` // Required + Sha *string `jsonapi:"attr,sha"` // Required + Official *bool `jsonapi:"attr,official,omitempty"` + Deprecated *bool `jsonapi:"attr,deprecated,omitempty"` + DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"` + Enabled *bool `jsonapi:"attr,enabled,omitempty"` + Beta *bool `jsonapi:"attr,beta,omitempty"` + Archs []*ToolVersionArchitecture `jsonapi:"attr,archs,omitempty"` } // AdminTerraformVersionUpdateOptions for updating terraform version. @@ -194,18 +209,25 @@ func (a *adminTerraformVersions) Delete(ctx context.Context, id string) error { } func (o AdminTerraformVersionCreateOptions) valid() error { - if (o == AdminTerraformVersionCreateOptions{}) { + if (reflect.DeepEqual(o, AdminTerraformVersionCreateOptions{})) { return ErrRequiredTFVerCreateOps } 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 bec375a5e..39e64006b 100644 --- a/admin_terraform_version_integration_test.go +++ b/admin_terraform_version_integration_test.go @@ -103,15 +103,22 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) { version := genSafeRandomTerraformVersion() t.Run("with valid options", func(t *testing.T) { + sha := String(genSha(t)) opts := AdminTerraformVersionCreateOptions{ Version: String(version), URL: String("https://www.hashicorp.com"), - Sha: String(genSha(t)), + Sha: sha, Deprecated: Bool(true), DeprecatedReason: String("Test Reason"), Official: Bool(false), Enabled: Bool(false), Beta: Bool(false), + Archs: []*ToolVersionArchitecture{{ + URL: "https://www.hashicorp.com", + Sha: *sha, + OS: linux, + Arch: amd64, + }}, } tfv, err := client.Admin.TerraformVersions.Create(ctx, opts) require.NoError(t, err) @@ -170,6 +177,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { t.Run("reads and updates", func(t *testing.T) { version := genSafeRandomTerraformVersion() + sha := String(genSha(t)) opts := AdminTerraformVersionCreateOptions{ Version: String(version), URL: String("https://www.hashicorp.com"), @@ -179,6 +187,12 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { DeprecatedReason: String("Test Reason"), Enabled: Bool(false), Beta: Bool(false), + Archs: []*ToolVersionArchitecture{{ + URL: "https://www.hashicorp.com", + Sha: *sha, + OS: linux, + Arch: amd64, + }}, } tfv, err := client.Admin.TerraformVersions.Create(ctx, opts) require.NoError(t, err) 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")