Skip to content

Commit 1219fe5

Browse files
authored
Merge branch 'main' into sebasslash/add-explorer-api
2 parents 2c834cb + 4dfce8f commit 1219fe5

32 files changed

+1189
-174
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@
44

55
* Add support for the Explorer API by @sebasslash [#1018](https://github.com/hashicorp/go-tfe/pull/1018)
66

7+
## Enhancements
8+
9+
* Add BETA support for adding custom project permission for variable sets `ProjectVariableSetsPermission` by @netramali [21879](https://github.com/hashicorp/atlas/pull/21879)
10+
11+
# v1.73.1
12+
13+
## Bug fixes
14+
15+
* Includes a critical security update in an upstream depdendency `hashicorp/go-slug` @NodyHub [#1025](https://github.com/hashicorp/go-tfe/pull/1025)
16+
* 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)
17+
18+
# v1.73.0
19+
20+
## Enhancements
21+
22+
* Add support for team notification configurations @notchairmk [#1016](https://github.com/hashicorp/go-tfe/pull/1016)
23+
24+
# v1.72.0
25+
26+
## Enhancements
27+
28+
* Add support for project level auto destroy settings @simonxmh [#1011](https://github.com/hashicorp/go-tfe/pull/1011)
29+
* 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)
30+
* Adds support to delete all tag bindings on either a project or workspace by @sebasslash [#1023](https://github.com/hashicorp/go-tfe/pull/1023)
31+
32+
733
# v1.71.0
834

935
## Enhancements

README.md

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -113,78 +113,6 @@ if err != nil {
113113

114114
For complete usage of the API client, see the [full package docs](https://pkg.go.dev/github.com/hashicorp/go-tfe).
115115

116-
## API Coverage
117-
118-
This API client covers most of the existing HCP Terraform API calls and is updated regularly to add new or missing endpoints.
119-
120-
- [x] Account
121-
- [x] Agents
122-
- [x] Agent Pools
123-
- [x] Agent Tokens
124-
- [x] Applies
125-
- [x] Audit Trails
126-
- [x] Changelog
127-
- [x] Comments
128-
- [x] Configuration Versions
129-
- [x] Cost Estimation
130-
- [ ] Feature Sets
131-
- [ ] Invoices
132-
- [x] IP Ranges
133-
- [x] Notification Configurations
134-
- [x] OAuth Clients
135-
- [x] OAuth Tokens
136-
- [x] Organizations
137-
- [x] Organization Memberships
138-
- [x] Organization Tags
139-
- [x] Organization Tokens
140-
- [x] Plan Exports
141-
- [x] Plans
142-
- [x] Policies
143-
- [x] Policy Checks
144-
- [x] Policy Sets
145-
- [x] Policy Set Parameters
146-
- [x] Private Registry
147-
- [x] Modules
148-
- [x] No-Code Modules
149-
- [x] Providers
150-
- [x] Provider Versions and Platforms
151-
- [x] GPG Keys
152-
- [x] Projects
153-
- [x] Runs
154-
- [x] Run Events
155-
- [x] Run Tasks
156-
- [x] Run Tasks Integration
157-
- [x] Run Triggers
158-
- [x] SSH Keys
159-
- [x] Stability Policy
160-
- [x] State Versions
161-
- [x] State Version Outputs
162-
- [ ] Subscriptions
163-
- [x] Team Access
164-
- [x] Team Membership
165-
- [x] Team Tokens
166-
- [x] Teams
167-
- [x] Test Runs
168-
- [x] User Tokens
169-
- [x] Users
170-
- [x] Variable Sets
171-
- [x] Variables
172-
- [ ] VCS Events
173-
- [x] Workspaces
174-
- [x] Workspace-Specific Variables
175-
- [x] Workspace Resources
176-
- [x] Admin
177-
- [x] Module Sharing
178-
- [x] Organizations
179-
- [x] Runs
180-
- [x] Settings
181-
- [x] Terraform Versions
182-
- [x] OPA Versions
183-
- [x] Sentinel Versions
184-
- [x] Users
185-
- [x] Workspaces
186-
187-
188116
## Examples
189117

190118
See the [examples directory](https://github.com/hashicorp/go-tfe/tree/main/examples).

admin_terraform_version.go

Lines changed: 38 additions & 17 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 ToolVersionArchitectureOptions struct {
66+
URL string `json:"url"`
67+
Sha string `json:"sha"`
68+
OS string `json:"os"`
69+
Arch string `json:"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 []*ToolVersionArchitectureOptions `jsonapi:"attr,archs,omitempty"`
8297
}
8398

8499
// AdminTerraformVersionUpdateOptions for updating terraform version.
@@ -153,7 +168,6 @@ func (a *adminTerraformVersions) Create(ctx context.Context, options AdminTerraf
153168
if err != nil {
154169
return nil, err
155170
}
156-
157171
return tfv, nil
158172
}
159173

@@ -194,18 +208,25 @@ func (a *adminTerraformVersions) Delete(ctx context.Context, id string) error {
194208
}
195209

196210
func (o AdminTerraformVersionCreateOptions) valid() error {
197-
if (o == AdminTerraformVersionCreateOptions{}) {
211+
if (reflect.DeepEqual(o, AdminTerraformVersionCreateOptions{})) {
198212
return ErrRequiredTFVerCreateOps
199213
}
200214
if !validString(o.Version) {
201215
return ErrRequiredVersion
202216
}
203-
if !validString(o.URL) {
204-
return ErrRequiredURL
205-
}
206-
if !validString(o.Sha) {
207-
return ErrRequiredSha
217+
if !o.validArch() && (!validString(o.URL) || !validString(o.Sha)) {
218+
return ErrRequiredArchOrURLAndSha
208219
}
209-
210220
return nil
211221
}
222+
223+
func (o AdminTerraformVersionCreateOptions) validArch() bool {
224+
var valid bool
225+
for _, a := range o.Archs {
226+
valid = validString(&a.URL) && validString(&a.Sha) && a.OS == linux && (a.Arch == amd64 || a.Arch == arm64)
227+
if valid {
228+
break
229+
}
230+
}
231+
return valid
232+
}

admin_terraform_version_integration_test.go

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,50 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) {
100100

101101
client := testClient(t)
102102
ctx := context.Background()
103-
version := genSafeRandomTerraformVersion()
104103

105-
t.Run("with valid options", func(t *testing.T) {
104+
t.Run("with valid options and archs", func(t *testing.T) {
106105
opts := AdminTerraformVersionCreateOptions{
107-
Version: String(version),
106+
Version: String(genSafeRandomTerraformVersion()),
107+
Deprecated: Bool(true),
108+
DeprecatedReason: String("Test Reason"),
109+
Official: Bool(false),
110+
Enabled: Bool(false),
111+
Beta: Bool(false),
112+
Archs: []*ToolVersionArchitectureOptions{
113+
{
114+
URL: "https://www.hashicorp.com",
115+
Sha: *String(genSha(t)),
116+
OS: linux,
117+
Arch: amd64,
118+
},
119+
{
120+
URL: "https://www.hashicorp.com",
121+
Sha: *String(genSha(t)),
122+
OS: linux,
123+
Arch: arm64,
124+
}},
125+
}
126+
tfv, err := client.Admin.TerraformVersions.Create(ctx, opts)
127+
require.NoError(t, err)
128+
129+
defer func() {
130+
deleteErr := client.Admin.TerraformVersions.Delete(ctx, tfv.ID)
131+
require.NoError(t, deleteErr)
132+
}()
133+
134+
assert.Equal(t, *opts.Version, tfv.Version)
135+
assert.Equal(t, *opts.URL, tfv.URL)
136+
assert.Equal(t, *opts.Sha, tfv.Sha)
137+
assert.Equal(t, *opts.Official, tfv.Official)
138+
assert.Equal(t, *opts.Deprecated, tfv.Deprecated)
139+
assert.Equal(t, *opts.DeprecatedReason, *tfv.DeprecatedReason)
140+
assert.Equal(t, *opts.Enabled, tfv.Enabled)
141+
assert.Equal(t, *opts.Beta, tfv.Beta)
142+
})
143+
144+
t.Run("with valid options, url, and sha", func(t *testing.T) {
145+
opts := AdminTerraformVersionCreateOptions{
146+
Version: String(genSafeRandomTerraformVersion()),
108147
URL: String("https://www.hashicorp.com"),
109148
Sha: String(genSha(t)),
110149
Deprecated: Bool(true),
@@ -170,6 +209,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
170209

171210
t.Run("reads and updates", func(t *testing.T) {
172211
version := genSafeRandomTerraformVersion()
212+
sha := String(genSha(t))
173213
opts := AdminTerraformVersionCreateOptions{
174214
Version: String(version),
175215
URL: String("https://www.hashicorp.com"),
@@ -179,6 +219,12 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
179219
DeprecatedReason: String("Test Reason"),
180220
Enabled: Bool(false),
181221
Beta: Bool(false),
222+
Archs: []*ToolVersionArchitectureOptions{{
223+
URL: "https://www.hashicorp.com",
224+
Sha: *sha,
225+
OS: linux,
226+
Arch: amd64,
227+
}},
182228
}
183229
tfv, err := client.Admin.TerraformVersions.Create(ctx, opts)
184230
require.NoError(t, err)

configuration_version_integration_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ func TestConfigurationVersionsUploadTarGzip(t *testing.T) {
311311
packer, err := slug.NewPacker(
312312
slug.DereferenceSymlinks(),
313313
slug.ApplyTerraformIgnore(),
314-
slug.AllowSymlinkTarget("/target/symlink/path/foo"),
315314
)
316315
require.NoError(t, err)
317316

errors.go

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

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

281+
ErrRequiredArchOrURLAndSha = errors.New("valid arch or url and sha is required")
282+
281283
ErrRequiredAPIURL = errors.New("API URL is required")
282284

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

example_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ func ExampleConfigurationVersions_UploadTarGzip() {
9090
}
9191

9292
packer, err := slug.NewPacker(
93-
slug.DereferenceSymlinks(), // dereferences symlinks
94-
slug.ApplyTerraformIgnore(), // ignores paths specified in .terraformignore
95-
slug.AllowSymlinkTarget("/some/path"), // allow certain symlink target paths
93+
slug.DereferenceSymlinks(), // dereferences symlinks
94+
slug.ApplyTerraformIgnore(), // ignores paths specified in .terraformignore
9695
)
9796
if err != nil {
9897
log.Fatal(err)
@@ -131,9 +130,8 @@ func ExampleRegistryModules_UploadTarGzip() {
131130
}
132131

133132
packer, err := slug.NewPacker(
134-
slug.DereferenceSymlinks(), // dereferences symlinks
135-
slug.ApplyTerraformIgnore(), // ignores paths specified in .terraformignore
136-
slug.AllowSymlinkTarget("/some/path"), // allow certain symlink target paths
133+
slug.DereferenceSymlinks(), // dereferences symlinks
134+
slug.ApplyTerraformIgnore(), // ignores paths specified in .terraformignore
137135
)
138136
if err != nil {
139137
log.Fatal(err)

examples/configuration_versions/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ func main() {
2222
}
2323

2424
packer, err := slug.NewPacker(
25-
slug.DereferenceSymlinks(), // dereferences symlinks
26-
slug.ApplyTerraformIgnore(), // ignores paths specified in .terraformignore
27-
slug.AllowSymlinkTarget("/some/path"), // allow certain symlink target paths
25+
slug.DereferenceSymlinks(), // dereferences symlinks
26+
slug.ApplyTerraformIgnore(), // ignores paths specified in .terraformignore
2827
)
2928
if err != nil {
3029
log.Fatal(err)

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+
}

0 commit comments

Comments
 (0)