Skip to content

Commit 6361be9

Browse files
[TF-23543] Patch Terraform Tool Version with Archs (#1047)
* add optional arch to update, add arch fields to responses * move arch update to its own test * Update CHANGELOG.md Co-authored-by: Natalie Todd <[email protected]> * fix changelog * update jsonapi 1.4.1, use 1 ToolVersionArchitecture struct --------- Co-authored-by: Natalie Todd <[email protected]>
1 parent 32d39c5 commit 6361be9

File tree

5 files changed

+105
-40
lines changed

5 files changed

+105
-40
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
## Bug fixes
4+
5+
* 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)
6+
37
# v1.75.0
48

59
## Enhancements

admin_terraform_version.go

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,25 @@ type adminTerraformVersions struct {
4949

5050
// AdminTerraformVersion represents a Terraform Version
5151
type AdminTerraformVersion struct {
52-
ID string `jsonapi:"primary,terraform-versions"`
53-
Version string `jsonapi:"attr,version"`
54-
URL string `jsonapi:"attr,url"`
55-
Sha string `jsonapi:"attr,sha"`
56-
Deprecated bool `jsonapi:"attr,deprecated"`
57-
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
58-
Official bool `jsonapi:"attr,official"`
59-
Enabled bool `jsonapi:"attr,enabled"`
60-
Beta bool `jsonapi:"attr,beta"`
61-
Usage int `jsonapi:"attr,usage"`
62-
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
52+
ID string `jsonapi:"primary,terraform-versions"`
53+
Version string `jsonapi:"attr,version"`
54+
URL string `jsonapi:"attr,url,omitempty"`
55+
Sha string `jsonapi:"attr,sha,omitempty"`
56+
Deprecated bool `jsonapi:"attr,deprecated"`
57+
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
58+
Official bool `jsonapi:"attr,official"`
59+
Enabled bool `jsonapi:"attr,enabled"`
60+
Beta bool `jsonapi:"attr,beta"`
61+
Usage int `jsonapi:"attr,usage"`
62+
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
63+
Archs []*ToolVersionArchitecture `jsonapi:"attr,archs,omitempty"`
6364
}
6465

65-
type ToolVersionArchitectureOptions struct {
66-
URL string `json:"url"`
67-
Sha string `json:"sha"`
68-
OS string `json:"os"`
69-
Arch string `json:"arch"`
66+
type ToolVersionArchitecture struct {
67+
URL string `jsonapi:"attr,url"`
68+
Sha string `jsonapi:"attr,sha"`
69+
OS string `jsonapi:"attr,os"`
70+
Arch string `jsonapi:"attr,arch"`
7071
}
7172

7273
// AdminTerraformVersionsListOptions represents the options for listing
@@ -84,30 +85,31 @@ type AdminTerraformVersionsListOptions struct {
8485
// AdminTerraformVersionCreateOptions for creating a terraform version.
8586
// https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/terraform-versions#request-body
8687
type AdminTerraformVersionCreateOptions struct {
87-
Type string `jsonapi:"primary,terraform-versions"`
88-
Version *string `jsonapi:"attr,version"` // Required
89-
URL *string `jsonapi:"attr,url"` // Required
90-
Sha *string `jsonapi:"attr,sha"` // Required
91-
Official *bool `jsonapi:"attr,official,omitempty"`
92-
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
93-
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
94-
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
95-
Beta *bool `jsonapi:"attr,beta,omitempty"`
96-
Archs []*ToolVersionArchitectureOptions `jsonapi:"attr,archs,omitempty"`
88+
Type string `jsonapi:"primary,terraform-versions"`
89+
Version *string `jsonapi:"attr,version"` // Required
90+
URL *string `jsonapi:"attr,url,omitempty"`
91+
Sha *string `jsonapi:"attr,sha,omitempty"`
92+
Official *bool `jsonapi:"attr,official,omitempty"`
93+
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
94+
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
95+
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
96+
Beta *bool `jsonapi:"attr,beta,omitempty"`
97+
Archs []*ToolVersionArchitecture `jsonapi:"attr,archs,omitempty"`
9798
}
9899

99100
// AdminTerraformVersionUpdateOptions for updating terraform version.
100101
// https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/terraform-versions#request-body
101102
type AdminTerraformVersionUpdateOptions struct {
102-
Type string `jsonapi:"primary,terraform-versions"`
103-
Version *string `jsonapi:"attr,version,omitempty"`
104-
URL *string `jsonapi:"attr,url,omitempty"`
105-
Sha *string `jsonapi:"attr,sha,omitempty"`
106-
Official *bool `jsonapi:"attr,official,omitempty"`
107-
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
108-
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
109-
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
110-
Beta *bool `jsonapi:"attr,beta,omitempty"`
103+
Type string `jsonapi:"primary,terraform-versions"`
104+
Version *string `jsonapi:"attr,version,omitempty"`
105+
URL *string `jsonapi:"attr,url,omitempty"`
106+
Sha *string `jsonapi:"attr,sha,omitempty"`
107+
Official *bool `jsonapi:"attr,official,omitempty"`
108+
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
109+
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
110+
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
111+
Beta *bool `jsonapi:"attr,beta,omitempty"`
112+
Archs []*ToolVersionArchitecture `jsonapi:"attr,archs,omitempty"`
111113
}
112114

113115
// AdminTerraformVersionsList represents a list of terraform versions.

admin_terraform_version_integration_test.go

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) {
109109
Official: Bool(false),
110110
Enabled: Bool(false),
111111
Beta: Bool(false),
112-
Archs: []*ToolVersionArchitectureOptions{
112+
Archs: []*ToolVersionArchitecture{
113113
{
114114
URL: "https://www.hashicorp.com",
115115
Sha: *String(genSha(t)),
@@ -137,6 +137,13 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) {
137137
assert.Equal(t, *opts.DeprecatedReason, *tfv.DeprecatedReason)
138138
assert.Equal(t, *opts.Enabled, tfv.Enabled)
139139
assert.Equal(t, *opts.Beta, tfv.Beta)
140+
assert.Equal(t, len(opts.Archs), len(tfv.Archs))
141+
for i, arch := range opts.Archs {
142+
assert.Equal(t, arch.URL, tfv.Archs[i].URL)
143+
assert.Equal(t, arch.Sha, tfv.Archs[i].Sha)
144+
assert.Equal(t, arch.OS, tfv.Archs[i].OS)
145+
assert.Equal(t, arch.Arch, tfv.Archs[i].Arch)
146+
}
140147
})
141148

142149
t.Run("with valid options, url, and sha", func(t *testing.T) {
@@ -217,7 +224,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
217224
DeprecatedReason: String("Test Reason"),
218225
Enabled: Bool(false),
219226
Beta: Bool(false),
220-
Archs: []*ToolVersionArchitectureOptions{{
227+
Archs: []*ToolVersionArchitecture{{
221228
URL: "https://www.hashicorp.com",
222229
Sha: *sha,
223230
OS: linux,
@@ -254,6 +261,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
254261
}
255262

256263
tfv, err = client.Admin.TerraformVersions.Update(ctx, id, updateOpts)
264+
257265
require.NoError(t, err)
258266

259267
assert.Equal(t, updateVersion, tfv.Version)
@@ -265,6 +273,57 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
265273
assert.Equal(t, *opts.Beta, tfv.Beta)
266274
})
267275

276+
t.Run("update with Archs", func(t *testing.T) {
277+
version := genSafeRandomTerraformVersion()
278+
sha := String(genSha(t))
279+
opts := AdminTerraformVersionCreateOptions{
280+
Version: String(version),
281+
URL: String("https://www.hashicorp.com"),
282+
Sha: String(genSha(t)),
283+
Official: Bool(false),
284+
Deprecated: Bool(true),
285+
DeprecatedReason: String("Test Reason"),
286+
Enabled: Bool(false),
287+
Beta: Bool(false),
288+
Archs: []*ToolVersionArchitecture{{
289+
URL: "https://www.hashicorp.com",
290+
Sha: *sha,
291+
OS: linux,
292+
Arch: amd64,
293+
}},
294+
}
295+
tfv, err := client.Admin.TerraformVersions.Create(ctx, opts)
296+
require.NoError(t, err)
297+
id := tfv.ID
298+
299+
defer func() {
300+
deleteErr := client.Admin.TerraformVersions.Delete(ctx, id)
301+
require.NoError(t, deleteErr)
302+
}()
303+
304+
updateVersion := genSafeRandomTerraformVersion()
305+
updateArchOpts := AdminTerraformVersionUpdateOptions{
306+
Version: String(updateVersion),
307+
Deprecated: Bool(false),
308+
Archs: []*ToolVersionArchitecture{{
309+
URL: "https://www.hashicorp.com",
310+
Sha: *sha,
311+
OS: linux,
312+
Arch: amd64,
313+
}},
314+
}
315+
316+
tfv, err = client.Admin.TerraformVersions.Update(ctx, id, updateArchOpts)
317+
require.NoError(t, err)
318+
319+
assert.Equal(t, len(tfv.Archs), 1)
320+
assert.Equal(t, updateArchOpts.Archs[0].URL, tfv.Archs[0].URL)
321+
assert.Equal(t, updateArchOpts.Archs[0].Sha, tfv.Archs[0].Sha)
322+
assert.Equal(t, updateArchOpts.Archs[0].OS, tfv.Archs[0].OS)
323+
assert.Equal(t, updateArchOpts.Archs[0].Arch, tfv.Archs[0].Arch)
324+
assert.Equal(t, updateVersion, tfv.Version)
325+
})
326+
268327
t.Run("with non-existent terraform version", func(t *testing.T) {
269328
randomID := "random-id"
270329
_, err := client.Admin.TerraformVersions.Read(ctx, randomID)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/hashicorp/go-slug v0.16.4
1010
github.com/hashicorp/go-uuid v1.0.3
1111
github.com/hashicorp/go-version v1.7.0
12-
github.com/hashicorp/jsonapi v1.3.2
12+
github.com/hashicorp/jsonapi v1.4.1
1313
github.com/stretchr/testify v1.10.0
1414
go.uber.org/mock v0.4.0
1515
golang.org/x/sync v0.10.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C
1616
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
1717
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
1818
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
19-
github.com/hashicorp/jsonapi v1.3.2 h1:gP3fX2ZT7qXi+PbwieptzkspIohO2kCSiBUvUTBAbMs=
20-
github.com/hashicorp/jsonapi v1.3.2/go.mod h1:kWfdn49yCjQvbpnvY1dxxAuAFzISwrrMDQOcu6NsFoM=
19+
github.com/hashicorp/jsonapi v1.4.1 h1:U6CZvnS70Sg7im0kpfhWAoF3NasLumaMndQhEWniHZA=
20+
github.com/hashicorp/jsonapi v1.4.1/go.mod h1:kWfdn49yCjQvbpnvY1dxxAuAFzISwrrMDQOcu6NsFoM=
2121
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
2222
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
2323
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)