diff --git a/CHANGELOG.md b/CHANGELOG.md index c007bb5b2..a8bd6bab7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ## Bug Fixes * Update dependency `github.com/hashicorp/go-slug` `v0.16.0` => `v0.16.3` to integrate latest changes. +* Fix bug in 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.72.0 diff --git a/admin_terraform_version.go b/admin_terraform_version.go index 78d75ce14..01a69f84b 100644 --- a/admin_terraform_version.go +++ b/admin_terraform_version.go @@ -62,11 +62,11 @@ 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"` +type ToolVersionArchitectureOptions struct { + URL string `json:"url"` + Sha string `json:"sha"` + OS string `json:"os"` + Arch string `json:"arch"` } // AdminTerraformVersionsListOptions represents the options for listing @@ -84,16 +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"` - Archs []*ToolVersionArchitecture `jsonapi:"attr,archs,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 []*ToolVersionArchitectureOptions `jsonapi:"attr,archs,omitempty"` } // AdminTerraformVersionUpdateOptions for updating terraform version. @@ -168,7 +168,6 @@ func (a *adminTerraformVersions) Create(ctx context.Context, options AdminTerraf if err != nil { return nil, err } - return tfv, nil } diff --git a/admin_terraform_version_integration_test.go b/admin_terraform_version_integration_test.go index 39e64006b..67898e256 100644 --- a/admin_terraform_version_integration_test.go +++ b/admin_terraform_version_integration_test.go @@ -100,25 +100,57 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) { client := testClient(t) ctx := context.Background() - version := genSafeRandomTerraformVersion() - t.Run("with valid options", func(t *testing.T) { - sha := String(genSha(t)) + t.Run("with valid options and archs", func(t *testing.T) { opts := AdminTerraformVersionCreateOptions{ - Version: String(version), + Version: String(genSafeRandomTerraformVersion()), + Deprecated: Bool(true), + DeprecatedReason: String("Test Reason"), + Official: Bool(false), + Enabled: Bool(false), + Beta: Bool(false), + Archs: []*ToolVersionArchitectureOptions{ + { + URL: "https://www.hashicorp.com", + Sha: *String(genSha(t)), + OS: linux, + Arch: amd64, + }, + { + URL: "https://www.hashicorp.com", + Sha: *String(genSha(t)), + OS: linux, + Arch: arm64, + }}, + } + tfv, err := client.Admin.TerraformVersions.Create(ctx, opts) + require.NoError(t, err) + + defer func() { + deleteErr := client.Admin.TerraformVersions.Delete(ctx, tfv.ID) + require.NoError(t, deleteErr) + }() + + assert.Equal(t, *opts.Version, tfv.Version) + assert.Equal(t, *opts.URL, tfv.URL) + assert.Equal(t, *opts.Sha, tfv.Sha) + assert.Equal(t, *opts.Official, tfv.Official) + assert.Equal(t, *opts.Deprecated, tfv.Deprecated) + assert.Equal(t, *opts.DeprecatedReason, *tfv.DeprecatedReason) + assert.Equal(t, *opts.Enabled, tfv.Enabled) + assert.Equal(t, *opts.Beta, tfv.Beta) + }) + + t.Run("with valid options, url, and sha", func(t *testing.T) { + opts := AdminTerraformVersionCreateOptions{ + Version: String(genSafeRandomTerraformVersion()), URL: String("https://www.hashicorp.com"), - Sha: sha, + Sha: String(genSha(t)), 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) @@ -187,7 +219,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { DeprecatedReason: String("Test Reason"), Enabled: Bool(false), Beta: Bool(false), - Archs: []*ToolVersionArchitecture{{ + Archs: []*ToolVersionArchitectureOptions{{ URL: "https://www.hashicorp.com", Sha: *sha, OS: linux,