Skip to content

Commit

Permalink
Add validation enforcing at least one valid arch or valid URL and SHA…
Browse files Browse the repository at this point in the history
… and update changelog
  • Loading branch information
natalie-todd committed Jan 3, 2025
1 parent b850462 commit ceaf38c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
## Enhancements

* Add support for project level auto destroy settings @simonxmh [#1011](https://github.com/hashicorp/go-tfe/pull/1011)
* Add `Archs` field to `AdminTerraformVersionCreateOptions` by @natalie-todd [#1022](https://github.com/hashicorp/go-tfe/pull/1022)

* Add 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.71.0

## Enhancements
Expand Down
25 changes: 19 additions & 6 deletions admin_terraform_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
// Compile-time proof of interface implementation.
var _ AdminTerraformVersions = (*adminTerraformVersions)(nil)

const (
linux = "linux"
amd64 = "amd64"
arm64 = "arm64"
)

// AdminTerraformVersions describes all the admin terraform versions related methods that
// the Terraform Enterprise API supports.
// Note that admin terraform versions are only available in Terraform Enterprise.
Expand Down Expand Up @@ -209,12 +215,19 @@ func (o AdminTerraformVersionCreateOptions) valid() error {
if !validString(o.Version) {
return ErrRequiredVersion
}
if !validString(o.URL) {
return ErrRequiredURL
if !o.validArch() && (!validString(o.URL) || !validString(o.Sha)) {
return ErrRequiredArchOrURLAndSha
}
if !validString(o.Sha) {
return ErrRequiredSha
}

return nil
}

func (o AdminTerraformVersionCreateOptions) validArch() bool {
var valid bool
for _, a := range o.Archs {
valid = validString(&a.URL) && validString(&a.Sha) && a.OS == linux && (a.Arch == amd64 || a.Arch == arm64)
if valid {
break
}
}
return valid
}
5 changes: 3 additions & 2 deletions admin_terraform_version_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) {
Archs: []*ToolVersionArchitecture{{
URL: "https://www.hashicorp.com",
Sha: *sha,
OS: "linux",
Arch: "amd64",
OS: linux,
Arch: amd64,
}},
}
tfv, err := client.Admin.TerraformVersions.Create(ctx, opts)
Expand Down Expand Up @@ -194,6 +194,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
Arch: "amd64",
}},
}

tfv, err := client.Admin.TerraformVersions.Create(ctx, opts)
require.NoError(t, err)
id := tfv.ID
Expand Down
2 changes: 2 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ var (

ErrRequiredURL = errors.New("url is required")

ErrRequiredArchOrURLAndSha = errors.New("valid arch or url and sha is required")

ErrRequiredAPIURL = errors.New("API URL is required")

ErrRequiredHTTPURL = errors.New("HTTP URL is required")
Expand Down

0 comments on commit ceaf38c

Please sign in to comment.