Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

## Bug fixes

* 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

## Enhancements
Expand Down
72 changes: 37 additions & 35 deletions admin_terraform_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +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 ToolVersionArchitectureOptions struct {
URL string `json:"url"`
Sha string `json:"sha"`
OS string `json:"os"`
Arch string `json:"arch"`
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
Expand All @@ -84,30 +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"` // 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"`
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"`
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.
Expand Down
63 changes: 61 additions & 2 deletions admin_terraform_version_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -217,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,
Expand Down Expand Up @@ -254,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)
Expand All @@ -265,6 +273,57 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
assert.Equal(t, *opts.Beta, tfv.Beta)
})

t.Run("update with Archs", func(t *testing.T) {
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: []*ToolVersionArchitecture{{
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, updateVersion, tfv.Version)
})

t.Run("with non-existent terraform version", func(t *testing.T) {
randomID := "random-id"
_, err := client.Admin.TerraformVersions.Read(ctx, randomID)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Loading