Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TF-23277] Fix archs field in terraform-versions CREATE request #1030

Merged
merged 4 commits into from
Jan 10, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 15 additions & 16 deletions admin_terraform_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
natalie-todd marked this conversation as resolved.
Show resolved Hide resolved
OS string `json:"os"`
Arch string `json:"arch"`
}

// AdminTerraformVersionsListOptions represents the options for listing
Expand All @@ -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.
Expand Down Expand Up @@ -168,7 +168,6 @@ func (a *adminTerraformVersions) Create(ctx context.Context, options AdminTerraf
if err != nil {
return nil, err
}

return tfv, nil
}

Expand Down
56 changes: 44 additions & 12 deletions admin_terraform_version_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
Loading