From 5987419795dc3a3ea4bfbcd74c0a0e1685156d8f Mon Sep 17 00:00:00 2001 From: Author Name Date: Wed, 29 Jan 2025 16:00:39 -0700 Subject: [PATCH 1/5] add optional arch to update, add arch fields to responses --- CHANGELOG.md | 4 ++ admin_terraform_version.go | 53 ++++++++++++--------- admin_terraform_version_integration_test.go | 30 ++++++++++++ 3 files changed, 65 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d2d78f7b..fd023938a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +## Bug fixes + +* Adds `Archs` field to update ToolVersions and includes architecture fields in responses. This provides BETA support, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @kelsi-hoyle [#1047](https://github.com/hashicorp/go-tfe/pull/1047) + # v1.75.0 ## Enhancements diff --git a/admin_terraform_version.go b/admin_terraform_version.go index 01a69f84b..3808b68e4 100644 --- a/admin_terraform_version.go +++ b/admin_terraform_version.go @@ -49,17 +49,25 @@ type adminTerraformVersions struct { // AdminTerraformVersion represents a Terraform Version type AdminTerraformVersion struct { - ID string `jsonapi:"primary,terraform-versions"` - Version string `jsonapi:"attr,version"` - URL string `jsonapi:"attr,url"` - Sha string `jsonapi:"attr,sha"` - Deprecated bool `jsonapi:"attr,deprecated"` - DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"` - Official bool `jsonapi:"attr,official"` - Enabled bool `jsonapi:"attr,enabled"` - Beta bool `jsonapi:"attr,beta"` - Usage int `jsonapi:"attr,usage"` - CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` + ID string `jsonapi:"primary,terraform-versions"` + Version string `jsonapi:"attr,version"` + URL string `jsonapi:"attr,url,omitempty"` + Sha string `jsonapi:"attr,sha,omitempty"` + Deprecated bool `jsonapi:"attr,deprecated"` + DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"` + Official bool `jsonapi:"attr,official"` + Enabled bool `jsonapi:"attr,enabled"` + Beta bool `jsonapi:"attr,beta"` + Usage int `jsonapi:"attr,usage"` + CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` + Archs []*ToolVersionArchitecture `jsonapi:"attr,archs,omitempty"` +} + +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 { @@ -86,8 +94,8 @@ type AdminTerraformVersionsListOptions struct { 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 + URL *string `jsonapi:"attr,url,omitempty"` + Sha *string `jsonapi:"attr,sha,omitempty"` Official *bool `jsonapi:"attr,official,omitempty"` Deprecated *bool `jsonapi:"attr,deprecated,omitempty"` DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"` @@ -99,15 +107,16 @@ type AdminTerraformVersionCreateOptions struct { // AdminTerraformVersionUpdateOptions for updating terraform version. // https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/terraform-versions#request-body type AdminTerraformVersionUpdateOptions struct { - Type string `jsonapi:"primary,terraform-versions"` - Version *string `jsonapi:"attr,version,omitempty"` - URL *string `jsonapi:"attr,url,omitempty"` - Sha *string `jsonapi:"attr,sha,omitempty"` - 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,omitempty"` + URL *string `jsonapi:"attr,url,omitempty"` + Sha *string `jsonapi:"attr,sha,omitempty"` + 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"` } // AdminTerraformVersionsList represents a list of terraform versions. diff --git a/admin_terraform_version_integration_test.go b/admin_terraform_version_integration_test.go index 10479a82c..eebafae3e 100644 --- a/admin_terraform_version_integration_test.go +++ b/admin_terraform_version_integration_test.go @@ -137,6 +137,13 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) { assert.Equal(t, *opts.DeprecatedReason, *tfv.DeprecatedReason) assert.Equal(t, *opts.Enabled, tfv.Enabled) assert.Equal(t, *opts.Beta, tfv.Beta) + assert.Equal(t, len(opts.Archs), len(tfv.Archs)) + for i, arch := range opts.Archs { + assert.Equal(t, arch.URL, tfv.Archs[i].URL) + assert.Equal(t, arch.Sha, tfv.Archs[i].Sha) + assert.Equal(t, arch.OS, tfv.Archs[i].OS) + assert.Equal(t, arch.Arch, tfv.Archs[i].Arch) + } }) t.Run("with valid options, url, and sha", func(t *testing.T) { @@ -263,6 +270,29 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { assert.Equal(t, *updateOpts.Deprecated, tfv.Deprecated) assert.Equal(t, *opts.Enabled, tfv.Enabled) assert.Equal(t, *opts.Beta, tfv.Beta) + + // Update using Archs + anotherUpdateVersion := genSafeRandomTerraformVersion() + updateArchOpts := AdminTerraformVersionUpdateOptions{ + Version: String(anotherUpdateVersion), + Deprecated: Bool(false), + Archs: []*ToolVersionArchitectureOptions{{ + URL: "https://www.hashicorp.com", + Sha: *sha, + OS: linux, + Arch: amd64, + }}, + } + + tfv, err = client.Admin.TerraformVersions.Update(ctx, id, updateArchOpts) + require.NoError(t, err) + + assert.Equal(t, len(tfv.Archs), 1) + assert.Equal(t, updateArchOpts.Archs[0].URL, tfv.Archs[0].URL) + assert.Equal(t, updateArchOpts.Archs[0].Sha, tfv.Archs[0].Sha) + assert.Equal(t, updateArchOpts.Archs[0].OS, tfv.Archs[0].OS) + assert.Equal(t, updateArchOpts.Archs[0].Arch, tfv.Archs[0].Arch) + assert.Equal(t, anotherUpdateVersion, tfv.Version) }) t.Run("with non-existent terraform version", func(t *testing.T) { From 2c6d860a053fd1c383a5e1ba3db555e507278ad1 Mon Sep 17 00:00:00 2001 From: Author Name Date: Thu, 30 Jan 2025 12:51:40 -0700 Subject: [PATCH 2/5] move arch update to its own test --- admin_terraform_version_integration_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/admin_terraform_version_integration_test.go b/admin_terraform_version_integration_test.go index eebafae3e..31c354a92 100644 --- a/admin_terraform_version_integration_test.go +++ b/admin_terraform_version_integration_test.go @@ -212,6 +212,8 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { client := testClient(t) ctx := context.Background() + var id string + t.Run("reads and updates", func(t *testing.T) { version := genSafeRandomTerraformVersion() sha := String(genSha(t)) @@ -233,7 +235,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { } tfv, err := client.Admin.TerraformVersions.Create(ctx, opts) require.NoError(t, err) - id := tfv.ID + id = tfv.ID defer func() { deleteErr := client.Admin.TerraformVersions.Delete(ctx, id) @@ -270,11 +272,13 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { assert.Equal(t, *updateOpts.Deprecated, tfv.Deprecated) assert.Equal(t, *opts.Enabled, tfv.Enabled) assert.Equal(t, *opts.Beta, tfv.Beta) + }) - // Update using Archs - anotherUpdateVersion := genSafeRandomTerraformVersion() + t.Run("update with Archs", func(t *testing.T) { + updateVersion := genSafeRandomTerraformVersion() + sha := String(genSha(t)) updateArchOpts := AdminTerraformVersionUpdateOptions{ - Version: String(anotherUpdateVersion), + Version: String(updateVersion), Deprecated: Bool(false), Archs: []*ToolVersionArchitectureOptions{{ URL: "https://www.hashicorp.com", @@ -284,7 +288,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { }}, } - tfv, err = client.Admin.TerraformVersions.Update(ctx, id, updateArchOpts) + tfv, err := client.Admin.TerraformVersions.Update(ctx, id, updateArchOpts) require.NoError(t, err) assert.Equal(t, len(tfv.Archs), 1) @@ -292,7 +296,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { assert.Equal(t, updateArchOpts.Archs[0].Sha, tfv.Archs[0].Sha) assert.Equal(t, updateArchOpts.Archs[0].OS, tfv.Archs[0].OS) assert.Equal(t, updateArchOpts.Archs[0].Arch, tfv.Archs[0].Arch) - assert.Equal(t, anotherUpdateVersion, tfv.Version) + assert.Equal(t, updateVersion, tfv.Version) }) t.Run("with non-existent terraform version", func(t *testing.T) { From b8ef87e93b9a7a13739ebfe6983c81962f7f5631 Mon Sep 17 00:00:00 2001 From: Author Name Date: Thu, 30 Jan 2025 13:15:51 -0700 Subject: [PATCH 3/5] Update CHANGELOG.md Co-authored-by: Natalie Todd --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd023938a..e74e57630 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Bug fixes -* Adds `Archs` field to update ToolVersions and includes architecture fields in responses. This provides BETA support, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @kelsi-hoyle [#1047](https://github.com/hashicorp/go-tfe/pull/1047) +* Adds `AdminTerraformVersionUpdateOptions` to `AdminTerraformVersionUpdateOptions` and `AdminTerraformVersion`. This provides BETA support, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @kelsi-hoyle [#1047](https://github.com/hashicorp/go-tfe/pull/1047) # v1.75.0 From ec4629b7f82c3d89e43707732f468d25aa97001a Mon Sep 17 00:00:00 2001 From: Author Name Date: Thu, 30 Jan 2025 13:23:11 -0700 Subject: [PATCH 4/5] fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e74e57630..abee5485e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Bug fixes -* Adds `AdminTerraformVersionUpdateOptions` to `AdminTerraformVersionUpdateOptions` and `AdminTerraformVersion`. This provides BETA support, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @kelsi-hoyle [#1047](https://github.com/hashicorp/go-tfe/pull/1047) +* Adds `ToolVersionArchitecture` to `AdminTerraformVersionUpdateOptions` and `AdminTerraformVersion`. This provides BETA support, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @kelsi-hoyle [#1047](https://github.com/hashicorp/go-tfe/pull/1047) # v1.75.0 From 4397429dcd8bde38b8dd6afe1a7a66b946c6d709 Mon Sep 17 00:00:00 2001 From: Author Name Date: Fri, 31 Jan 2025 10:00:49 -0700 Subject: [PATCH 5/5] update jsonapi 1.4.1, use 1 ToolVersionArchitecture struct --- admin_terraform_version.go | 47 +++++++++------------ admin_terraform_version_integration_test.go | 41 ++++++++++++++---- go.mod | 2 +- go.sum | 4 +- 4 files changed, 56 insertions(+), 38 deletions(-) diff --git a/admin_terraform_version.go b/admin_terraform_version.go index 3808b68e4..7e170722d 100644 --- a/admin_terraform_version.go +++ b/admin_terraform_version.go @@ -70,13 +70,6 @@ type ToolVersionArchitecture struct { 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 // terraform versions. type AdminTerraformVersionsListOptions struct { @@ -92,31 +85,31 @@ 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,omitempty"` - Sha *string `jsonapi:"attr,sha,omitempty"` - 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"` + Type string `jsonapi:"primary,terraform-versions"` + Version *string `jsonapi:"attr,version"` // Required + URL *string `jsonapi:"attr,url,omitempty"` + Sha *string `jsonapi:"attr,sha,omitempty"` + 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. // https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/terraform-versions#request-body type AdminTerraformVersionUpdateOptions struct { - Type string `jsonapi:"primary,terraform-versions"` - Version *string `jsonapi:"attr,version,omitempty"` - URL *string `jsonapi:"attr,url,omitempty"` - Sha *string `jsonapi:"attr,sha,omitempty"` - 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"` + Type string `jsonapi:"primary,terraform-versions"` + Version *string `jsonapi:"attr,version,omitempty"` + URL *string `jsonapi:"attr,url,omitempty"` + Sha *string `jsonapi:"attr,sha,omitempty"` + 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"` } // AdminTerraformVersionsList represents a list of terraform versions. diff --git a/admin_terraform_version_integration_test.go b/admin_terraform_version_integration_test.go index 31c354a92..b5b25de41 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: []*ToolVersionArchitectureOptions{ + Archs: []*ToolVersionArchitecture{ { URL: "https://www.hashicorp.com", Sha: *String(genSha(t)), @@ -212,8 +212,6 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { client := testClient(t) ctx := context.Background() - var id string - t.Run("reads and updates", func(t *testing.T) { version := genSafeRandomTerraformVersion() sha := String(genSha(t)) @@ -226,7 +224,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { DeprecatedReason: String("Test Reason"), Enabled: Bool(false), Beta: Bool(false), - Archs: []*ToolVersionArchitectureOptions{{ + Archs: []*ToolVersionArchitecture{{ URL: "https://www.hashicorp.com", Sha: *sha, OS: linux, @@ -235,7 +233,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { } tfv, err := client.Admin.TerraformVersions.Create(ctx, opts) require.NoError(t, err) - id = tfv.ID + id := tfv.ID defer func() { deleteErr := client.Admin.TerraformVersions.Delete(ctx, id) @@ -263,6 +261,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { } tfv, err = client.Admin.TerraformVersions.Update(ctx, id, updateOpts) + require.NoError(t, err) assert.Equal(t, updateVersion, tfv.Version) @@ -275,12 +274,38 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { }) t.Run("update with Archs", func(t *testing.T) { - updateVersion := genSafeRandomTerraformVersion() + version := genSafeRandomTerraformVersion() sha := String(genSha(t)) + opts := AdminTerraformVersionCreateOptions{ + Version: String(version), + URL: String("https://www.hashicorp.com"), + Sha: String(genSha(t)), + Official: Bool(false), + Deprecated: Bool(true), + 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) + id := tfv.ID + + defer func() { + deleteErr := client.Admin.TerraformVersions.Delete(ctx, id) + require.NoError(t, deleteErr) + }() + + updateVersion := genSafeRandomTerraformVersion() updateArchOpts := AdminTerraformVersionUpdateOptions{ Version: String(updateVersion), Deprecated: Bool(false), - Archs: []*ToolVersionArchitectureOptions{{ + Archs: []*ToolVersionArchitecture{{ URL: "https://www.hashicorp.com", Sha: *sha, OS: linux, @@ -288,7 +313,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { }}, } - tfv, err := client.Admin.TerraformVersions.Update(ctx, id, updateArchOpts) + tfv, err = client.Admin.TerraformVersions.Update(ctx, id, updateArchOpts) require.NoError(t, err) assert.Equal(t, len(tfv.Archs), 1) diff --git a/go.mod b/go.mod index 239f6c44a..056403310 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/hashicorp/go-slug v0.16.4 github.com/hashicorp/go-uuid v1.0.3 github.com/hashicorp/go-version v1.7.0 - github.com/hashicorp/jsonapi v1.3.2 + github.com/hashicorp/jsonapi v1.4.1 github.com/stretchr/testify v1.10.0 go.uber.org/mock v0.4.0 golang.org/x/sync v0.10.0 diff --git a/go.sum b/go.sum index 77076d0a4..717a98641 100644 --- a/go.sum +++ b/go.sum @@ -16,8 +16,8 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/jsonapi v1.3.2 h1:gP3fX2ZT7qXi+PbwieptzkspIohO2kCSiBUvUTBAbMs= -github.com/hashicorp/jsonapi v1.3.2/go.mod h1:kWfdn49yCjQvbpnvY1dxxAuAFzISwrrMDQOcu6NsFoM= +github.com/hashicorp/jsonapi v1.4.1 h1:U6CZvnS70Sg7im0kpfhWAoF3NasLumaMndQhEWniHZA= +github.com/hashicorp/jsonapi v1.4.1/go.mod h1:kWfdn49yCjQvbpnvY1dxxAuAFzISwrrMDQOcu6NsFoM= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=