Skip to content

Commit 3b68b95

Browse files
committed
Merge remote-tracking branch 'origin/main' into jfreda/add-team-notification-configs
2 parents fc1e263 + f215e07 commit 3b68b95

15 files changed

+376
-45
lines changed

CHANGELOG.md

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

3+
# v1.72.0
4+
5+
## Enhancements
6+
7+
* Add support for project level auto destroy settings @simonxmh [#1011](https://github.com/hashicorp/go-tfe/pull/1011)
8+
* 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)
9+
* Adds support to delete all tag bindings on either a project or workspace by @sebasslash [#1023](https://github.com/hashicorp/go-tfe/pull/1023)
10+
311
# v1.71.0
412

513
## Enhancements

admin_terraform_version.go

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ import (
77
"context"
88
"fmt"
99
"net/url"
10+
"reflect"
1011
"time"
1112
)
1213

1314
// Compile-time proof of interface implementation.
1415
var _ AdminTerraformVersions = (*adminTerraformVersions)(nil)
1516

17+
const (
18+
linux = "linux"
19+
amd64 = "amd64"
20+
arm64 = "arm64"
21+
)
22+
1623
// AdminTerraformVersions describes all the admin terraform versions related methods that
1724
// the Terraform Enterprise API supports.
1825
// Note that admin terraform versions are only available in Terraform Enterprise.
@@ -55,6 +62,13 @@ type AdminTerraformVersion struct {
5562
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
5663
}
5764

65+
type ToolVersionArchitecture struct {
66+
URL string `jsonapi:"attr,url"`
67+
Sha string `jsonapi:"attr,sha"`
68+
OS string `jsonapi:"attr,os"`
69+
Arch string `jsonapi:"attr,arch"`
70+
}
71+
5872
// AdminTerraformVersionsListOptions represents the options for listing
5973
// terraform versions.
6074
type AdminTerraformVersionsListOptions struct {
@@ -70,15 +84,16 @@ type AdminTerraformVersionsListOptions struct {
7084
// AdminTerraformVersionCreateOptions for creating a terraform version.
7185
// https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/terraform-versions#request-body
7286
type AdminTerraformVersionCreateOptions struct {
73-
Type string `jsonapi:"primary,terraform-versions"`
74-
Version *string `jsonapi:"attr,version"` // Required
75-
URL *string `jsonapi:"attr,url"` // Required
76-
Sha *string `jsonapi:"attr,sha"` // Required
77-
Official *bool `jsonapi:"attr,official,omitempty"`
78-
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
79-
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
80-
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
81-
Beta *bool `jsonapi:"attr,beta,omitempty"`
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 []*ToolVersionArchitecture `jsonapi:"attr,archs,omitempty"`
8297
}
8398

8499
// AdminTerraformVersionUpdateOptions for updating terraform version.
@@ -194,18 +209,25 @@ func (a *adminTerraformVersions) Delete(ctx context.Context, id string) error {
194209
}
195210

196211
func (o AdminTerraformVersionCreateOptions) valid() error {
197-
if (o == AdminTerraformVersionCreateOptions{}) {
212+
if (reflect.DeepEqual(o, AdminTerraformVersionCreateOptions{})) {
198213
return ErrRequiredTFVerCreateOps
199214
}
200215
if !validString(o.Version) {
201216
return ErrRequiredVersion
202217
}
203-
if !validString(o.URL) {
204-
return ErrRequiredURL
218+
if !o.validArch() && (!validString(o.URL) || !validString(o.Sha)) {
219+
return ErrRequiredArchOrURLAndSha
205220
}
206-
if !validString(o.Sha) {
207-
return ErrRequiredSha
208-
}
209-
210221
return nil
211222
}
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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,22 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) {
103103
version := genSafeRandomTerraformVersion()
104104

105105
t.Run("with valid options", func(t *testing.T) {
106+
sha := String(genSha(t))
106107
opts := AdminTerraformVersionCreateOptions{
107108
Version: String(version),
108109
URL: String("https://www.hashicorp.com"),
109-
Sha: String(genSha(t)),
110+
Sha: sha,
110111
Deprecated: Bool(true),
111112
DeprecatedReason: String("Test Reason"),
112113
Official: Bool(false),
113114
Enabled: Bool(false),
114115
Beta: Bool(false),
116+
Archs: []*ToolVersionArchitecture{{
117+
URL: "https://www.hashicorp.com",
118+
Sha: *sha,
119+
OS: linux,
120+
Arch: amd64,
121+
}},
115122
}
116123
tfv, err := client.Admin.TerraformVersions.Create(ctx, opts)
117124
require.NoError(t, err)
@@ -170,6 +177,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
170177

171178
t.Run("reads and updates", func(t *testing.T) {
172179
version := genSafeRandomTerraformVersion()
180+
sha := String(genSha(t))
173181
opts := AdminTerraformVersionCreateOptions{
174182
Version: String(version),
175183
URL: String("https://www.hashicorp.com"),
@@ -179,6 +187,12 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
179187
DeprecatedReason: String("Test Reason"),
180188
Enabled: Bool(false),
181189
Beta: Bool(false),
190+
Archs: []*ToolVersionArchitecture{{
191+
URL: "https://www.hashicorp.com",
192+
Sha: *sha,
193+
OS: linux,
194+
Arch: amd64,
195+
}},
182196
}
183197
tfv, err := client.Admin.TerraformVersions.Create(ctx, opts)
184198
require.NoError(t, err)

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")

examples/projects/main.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package main
5+
6+
import (
7+
"context"
8+
"log"
9+
10+
tfe "github.com/hashicorp/go-tfe"
11+
12+
"github.com/hashicorp/jsonapi"
13+
)
14+
15+
func main() {
16+
config := &tfe.Config{
17+
Token: "insert-your-token-here",
18+
RetryServerErrors: true,
19+
}
20+
21+
client, err := tfe.NewClient(config)
22+
if err != nil {
23+
log.Fatal(err)
24+
}
25+
26+
// Create a context
27+
ctx := context.Background()
28+
29+
// Create a new project
30+
p, err := client.Projects.Create(ctx, "org-test", tfe.ProjectCreateOptions{
31+
Name: "my-app-tst",
32+
})
33+
if err != nil {
34+
log.Fatal(err)
35+
}
36+
37+
// Update the project auto destroy activity duration
38+
p, err = client.Projects.Update(ctx, p.ID, tfe.ProjectUpdateOptions{
39+
AutoDestroyActivityDuration: jsonapi.NewNullableAttrWithValue("3d"),
40+
})
41+
if err != nil {
42+
log.Fatal(err)
43+
}
44+
45+
// Disable auto destroy
46+
p, err = client.Projects.Update(ctx, p.ID, tfe.ProjectUpdateOptions{
47+
AutoDestroyActivityDuration: jsonapi.NewNullNullableAttr[string](),
48+
})
49+
if err != nil {
50+
log.Fatal(err)
51+
}
52+
53+
err = client.Projects.Delete(ctx, p.ID)
54+
if err != nil {
55+
log.Fatal(err)
56+
}
57+
}

examples/workspaces/main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,21 @@ func main() {
2727

2828
// Create a new workspace
2929
w, err := client.Workspaces.Create(ctx, "org-name", tfe.WorkspaceCreateOptions{
30-
Name: tfe.String("my-app-tst"),
31-
AutoDestroyAt: tfe.NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)),
30+
Name: tfe.String("my-app-tst"),
31+
AutoDestroyAt: tfe.NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)),
32+
InheritsProjectAutoDestroy: tfe.Bool(false),
3233
})
3334
if err != nil {
3435
log.Fatal(err)
3536
}
3637

3738
// Update the workspace
3839
w, err = client.Workspaces.Update(ctx, "org-name", w.Name, tfe.WorkspaceUpdateOptions{
39-
AutoApply: tfe.Bool(false),
40-
TerraformVersion: tfe.String("0.11.1"),
41-
WorkingDirectory: tfe.String("my-app/infra"),
42-
AutoDestroyAt: tfe.NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)),
40+
AutoApply: tfe.Bool(false),
41+
TerraformVersion: tfe.String("0.11.1"),
42+
WorkingDirectory: tfe.String("my-app/infra"),
43+
AutoDestroyAt: tfe.NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)),
44+
InheritsProjectAutoDestroy: tfe.Bool(false),
4345
})
4446
if err != nil {
4547
log.Fatal(err)

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/hashicorp/go-slug v0.16.0
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.1
12+
github.com/hashicorp/jsonapi v1.3.2
1313
github.com/stretchr/testify v1.9.0
1414
go.uber.org/mock v0.4.0
1515
golang.org/x/sync v0.8.0
@@ -22,5 +22,3 @@ require (
2222
golang.org/x/sys v0.25.0 // indirect
2323
gopkg.in/yaml.v3 v3.0.1 // indirect
2424
)
25-
26-
replace github.com/hashicorp/jsonapi => github.com/notchairmk/jsonapi v0.0.0-20241223221631-b0c6a5b7edd8

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +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=
1921
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
2022
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
2123
github.com/notchairmk/jsonapi v0.0.0-20241223221631-b0c6a5b7edd8 h1:Nll3UptyKamtMP60oCHnRKI3l/kgadZHKQ6/uLYPyVM=

mocks/project_mocks.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/workspace_mocks.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)