Skip to content

Commit 56eeb74

Browse files
committed
Add validation enforcing at least one valid arch or valid URL and SHA and update changelog
1 parent b850462 commit 56eeb74

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
## Enhancements
44

55
* Add support for project level auto destroy settings @simonxmh [#1011](https://github.com/hashicorp/go-tfe/pull/1011)
6-
* Add `Archs` field to `AdminTerraformVersionCreateOptions` by @natalie-todd [#1022](https://github.com/hashicorp/go-tfe/pull/1022)
7-
6+
* 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)
7+
88
# v1.71.0
99

1010
## Enhancements

admin_terraform_version.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import (
1414
// Compile-time proof of interface implementation.
1515
var _ AdminTerraformVersions = (*adminTerraformVersions)(nil)
1616

17+
const (
18+
linux = "linux"
19+
amd64 = "amd64"
20+
arm64 = "arm64"
21+
)
22+
1723
// AdminTerraformVersions describes all the admin terraform versions related methods that
1824
// the Terraform Enterprise API supports.
1925
// Note that admin terraform versions are only available in Terraform Enterprise.
@@ -209,12 +215,19 @@ func (o AdminTerraformVersionCreateOptions) valid() error {
209215
if !validString(o.Version) {
210216
return ErrRequiredVersion
211217
}
212-
if !validString(o.URL) {
213-
return ErrRequiredURL
218+
if !o.validArch() && (!validString(o.URL) || !validString(o.Sha)) {
219+
return ErrRequiredArchOrURLAndSha
214220
}
215-
if !validString(o.Sha) {
216-
return ErrRequiredSha
217-
}
218-
219221
return nil
220222
}
223+
224+
func (o AdminTerraformVersionCreateOptions) validArch() bool {
225+
var valid bool
226+
for _, a := range o.Archs {
227+
valid = validString(&a.URL) && validString(&a.Sha) && a.OS == linux && (a.Arch == amd64 || a.Arch == arm64)
228+
if valid {
229+
break
230+
}
231+
}
232+
return valid
233+
}

admin_terraform_version_integration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) {
116116
Archs: []*ToolVersionArchitecture{{
117117
URL: "https://www.hashicorp.com",
118118
Sha: *sha,
119-
OS: "linux",
120-
Arch: "amd64",
119+
OS: linux,
120+
Arch: amd64,
121121
}},
122122
}
123123
tfv, err := client.Admin.TerraformVersions.Create(ctx, opts)
@@ -190,8 +190,8 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
190190
Archs: []*ToolVersionArchitecture{{
191191
URL: "https://www.hashicorp.com",
192192
Sha: *sha,
193-
OS: "linux",
194-
Arch: "amd64",
193+
OS: linux,
194+
Arch: amd64,
195195
}},
196196
}
197197
tfv, err := client.Admin.TerraformVersions.Create(ctx, opts)

errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ var (
274274

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

277+
ErrRequiredArchOrURLAndSha = errors.New("valid arch or url and sha is required")
278+
277279
ErrRequiredAPIURL = errors.New("API URL is required")
278280

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

0 commit comments

Comments
 (0)