From d43e66705dae69a8165510e2e6f8095e0433d6c9 Mon Sep 17 00:00:00 2001 From: natalie-todd Date: Wed, 8 Jan 2025 13:28:40 -0800 Subject: [PATCH 1/3] Use json instead of jsonapi for Archs --- CHANGELOG.md | 4 ++++ admin_terraform_version.go | 9 ++++---- admin_terraform_version_integration_test.go | 25 ++++++++++++--------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aafd1951f..f0498491c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ * Add support for team notification configurations @notchairmk [#1016](https://github.com/hashicorp/go-tfe/pull/1016) +## Bug Fixes + +* Fixes a 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 ## Enhancements diff --git a/admin_terraform_version.go b/admin_terraform_version.go index 78d75ce14..e1d00561f 100644 --- a/admin_terraform_version.go +++ b/admin_terraform_version.go @@ -63,10 +63,10 @@ type AdminTerraformVersion struct { } type ToolVersionArchitecture struct { - URL string `jsonapi:"attr,url"` - Sha string `jsonapi:"attr,sha"` - OS string `jsonapi:"attr,os"` - Arch string `jsonapi:"attr,arch"` + URL string `json:"url"` + Sha string `json:"sha"` + OS string `json:"os"` + Arch string `json:"arch"` } // AdminTerraformVersionsListOptions represents the options for listing @@ -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..dfd79baca 100644 --- a/admin_terraform_version_integration_test.go +++ b/admin_terraform_version_integration_test.go @@ -100,25 +100,28 @@ 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)) opts := AdminTerraformVersionCreateOptions{ - Version: String(version), - URL: String("https://www.hashicorp.com"), - Sha: sha, + Version: String(genSafeRandomTerraformVersion()), 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, - }}, + Archs: []*ToolVersionArchitecture{ + { + 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) From 53fa83f8256ffe5259610b459ece724d309d757f Mon Sep 17 00:00:00 2001 From: natalie-todd Date: Thu, 9 Jan 2025 15:12:05 -0800 Subject: [PATCH 2/3] Add test for valid options, url, and sha --- admin_terraform_version_integration_test.go | 31 ++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/admin_terraform_version_integration_test.go b/admin_terraform_version_integration_test.go index dfd79baca..defffeb70 100644 --- a/admin_terraform_version_integration_test.go +++ b/admin_terraform_version_integration_test.go @@ -101,7 +101,7 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) { client := testClient(t) ctx := context.Background() - t.Run("with valid options", func(t *testing.T) { + t.Run("with valid options and archs", func(t *testing.T) { opts := AdminTerraformVersionCreateOptions{ Version: String(genSafeRandomTerraformVersion()), Deprecated: Bool(true), @@ -141,6 +141,35 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) { 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: String(genSha(t)), + Deprecated: Bool(true), + DeprecatedReason: String("Test Reason"), + Official: Bool(false), + Enabled: Bool(false), + Beta: Bool(false), + } + 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 only required options", func(t *testing.T) { version := genSafeRandomTerraformVersion() opts := AdminTerraformVersionCreateOptions{ From f42957d73c7e7bc0309ddf50cf150b8e6ec0dcdf Mon Sep 17 00:00:00 2001 From: natalie-todd Date: Fri, 10 Jan 2025 10:02:27 -0800 Subject: [PATCH 3/3] Rename ToolVersionArchitecture to ToolVersionArchitectureOptions for convention --- admin_terraform_version.go | 22 ++++++++++----------- admin_terraform_version_integration_test.go | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/admin_terraform_version.go b/admin_terraform_version.go index e1d00561f..01a69f84b 100644 --- a/admin_terraform_version.go +++ b/admin_terraform_version.go @@ -62,7 +62,7 @@ type AdminTerraformVersion struct { CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` } -type ToolVersionArchitecture struct { +type ToolVersionArchitectureOptions struct { URL string `json:"url"` Sha string `json:"sha"` OS string `json:"os"` @@ -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. diff --git a/admin_terraform_version_integration_test.go b/admin_terraform_version_integration_test.go index defffeb70..67898e256 100644 --- a/admin_terraform_version_integration_test.go +++ b/admin_terraform_version_integration_test.go @@ -109,7 +109,7 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) { Official: Bool(false), Enabled: Bool(false), Beta: Bool(false), - Archs: []*ToolVersionArchitecture{ + Archs: []*ToolVersionArchitectureOptions{ { URL: "https://www.hashicorp.com", Sha: *String(genSha(t)), @@ -219,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,