Skip to content

Commit

Permalink
Merge branch 'main' into sebasslash/add-explorer-api
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrombley authored Jan 15, 2025
2 parents 2c834cb + 4dfce8f commit 1219fe5
Show file tree
Hide file tree
Showing 32 changed files with 1,189 additions and 174 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@

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

## Enhancements

* Add BETA support for adding custom project permission for variable sets `ProjectVariableSetsPermission` by @netramali [21879](https://github.com/hashicorp/atlas/pull/21879)

# v1.73.1

## Bug fixes

* Includes a critical security update in an upstream depdendency `hashicorp/go-slug` @NodyHub [#1025](https://github.com/hashicorp/go-tfe/pull/1025)
* 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.73.0

## Enhancements

* Add support for team notification configurations @notchairmk [#1016](https://github.com/hashicorp/go-tfe/pull/1016)

# v1.72.0

## Enhancements

* Add support for project level auto destroy settings @simonxmh [#1011](https://github.com/hashicorp/go-tfe/pull/1011)
* 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)
* Adds support to delete all tag bindings on either a project or workspace by @sebasslash [#1023](https://github.com/hashicorp/go-tfe/pull/1023)


# v1.71.0

## Enhancements
Expand Down
72 changes: 0 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,78 +113,6 @@ if err != nil {

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

## API Coverage

This API client covers most of the existing HCP Terraform API calls and is updated regularly to add new or missing endpoints.

- [x] Account
- [x] Agents
- [x] Agent Pools
- [x] Agent Tokens
- [x] Applies
- [x] Audit Trails
- [x] Changelog
- [x] Comments
- [x] Configuration Versions
- [x] Cost Estimation
- [ ] Feature Sets
- [ ] Invoices
- [x] IP Ranges
- [x] Notification Configurations
- [x] OAuth Clients
- [x] OAuth Tokens
- [x] Organizations
- [x] Organization Memberships
- [x] Organization Tags
- [x] Organization Tokens
- [x] Plan Exports
- [x] Plans
- [x] Policies
- [x] Policy Checks
- [x] Policy Sets
- [x] Policy Set Parameters
- [x] Private Registry
- [x] Modules
- [x] No-Code Modules
- [x] Providers
- [x] Provider Versions and Platforms
- [x] GPG Keys
- [x] Projects
- [x] Runs
- [x] Run Events
- [x] Run Tasks
- [x] Run Tasks Integration
- [x] Run Triggers
- [x] SSH Keys
- [x] Stability Policy
- [x] State Versions
- [x] State Version Outputs
- [ ] Subscriptions
- [x] Team Access
- [x] Team Membership
- [x] Team Tokens
- [x] Teams
- [x] Test Runs
- [x] User Tokens
- [x] Users
- [x] Variable Sets
- [x] Variables
- [ ] VCS Events
- [x] Workspaces
- [x] Workspace-Specific Variables
- [x] Workspace Resources
- [x] Admin
- [x] Module Sharing
- [x] Organizations
- [x] Runs
- [x] Settings
- [x] Terraform Versions
- [x] OPA Versions
- [x] Sentinel Versions
- [x] Users
- [x] Workspaces


## Examples

See the [examples directory](https://github.com/hashicorp/go-tfe/tree/main/examples).
Expand Down
55 changes: 38 additions & 17 deletions admin_terraform_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import (
"context"
"fmt"
"net/url"
"reflect"
"time"
)

// 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 @@ -55,6 +62,13 @@ type AdminTerraformVersion struct {
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
}

type ToolVersionArchitectureOptions struct {
URL string `json:"url"`
Sha string `json:"sha"`
OS string `json:"os"`
Arch string `json:"arch"`
}

// AdminTerraformVersionsListOptions represents the options for listing
// terraform versions.
type AdminTerraformVersionsListOptions struct {
Expand All @@ -70,15 +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"`
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 @@ -153,7 +168,6 @@ func (a *adminTerraformVersions) Create(ctx context.Context, options AdminTerraf
if err != nil {
return nil, err
}

return tfv, nil
}

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

func (o AdminTerraformVersionCreateOptions) valid() error {
if (o == AdminTerraformVersionCreateOptions{}) {
if (reflect.DeepEqual(o, AdminTerraformVersionCreateOptions{})) {
return ErrRequiredTFVerCreateOps
}
if !validString(o.Version) {
return ErrRequiredVersion
}
if !validString(o.URL) {
return ErrRequiredURL
}
if !validString(o.Sha) {
return ErrRequiredSha
if !o.validArch() && (!validString(o.URL) || !validString(o.Sha)) {
return ErrRequiredArchOrURLAndSha
}

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
}
52 changes: 49 additions & 3 deletions admin_terraform_version_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,50 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) {

client := testClient(t)
ctx := context.Background()
version := genSafeRandomTerraformVersion()

t.Run("with valid options", func(t *testing.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: String(genSha(t)),
Deprecated: Bool(true),
Expand Down Expand Up @@ -170,6 +209,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {

t.Run("reads and updates", func(t *testing.T) {
version := genSafeRandomTerraformVersion()
sha := String(genSha(t))
opts := AdminTerraformVersionCreateOptions{
Version: String(version),
URL: String("https://www.hashicorp.com"),
Expand All @@ -179,6 +219,12 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
DeprecatedReason: String("Test Reason"),
Enabled: Bool(false),
Beta: Bool(false),
Archs: []*ToolVersionArchitectureOptions{{
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
1 change: 0 additions & 1 deletion configuration_version_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ func TestConfigurationVersionsUploadTarGzip(t *testing.T) {
packer, err := slug.NewPacker(
slug.DereferenceSymlinks(),
slug.ApplyTerraformIgnore(),
slug.AllowSymlinkTarget("/target/symlink/path/foo"),
)
require.NoError(t, err)

Expand Down
2 changes: 2 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,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
10 changes: 4 additions & 6 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ func ExampleConfigurationVersions_UploadTarGzip() {
}

packer, err := slug.NewPacker(
slug.DereferenceSymlinks(), // dereferences symlinks
slug.ApplyTerraformIgnore(), // ignores paths specified in .terraformignore
slug.AllowSymlinkTarget("/some/path"), // allow certain symlink target paths
slug.DereferenceSymlinks(), // dereferences symlinks
slug.ApplyTerraformIgnore(), // ignores paths specified in .terraformignore
)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -131,9 +130,8 @@ func ExampleRegistryModules_UploadTarGzip() {
}

packer, err := slug.NewPacker(
slug.DereferenceSymlinks(), // dereferences symlinks
slug.ApplyTerraformIgnore(), // ignores paths specified in .terraformignore
slug.AllowSymlinkTarget("/some/path"), // allow certain symlink target paths
slug.DereferenceSymlinks(), // dereferences symlinks
slug.ApplyTerraformIgnore(), // ignores paths specified in .terraformignore
)
if err != nil {
log.Fatal(err)
Expand Down
5 changes: 2 additions & 3 deletions examples/configuration_versions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ func main() {
}

packer, err := slug.NewPacker(
slug.DereferenceSymlinks(), // dereferences symlinks
slug.ApplyTerraformIgnore(), // ignores paths specified in .terraformignore
slug.AllowSymlinkTarget("/some/path"), // allow certain symlink target paths
slug.DereferenceSymlinks(), // dereferences symlinks
slug.ApplyTerraformIgnore(), // ignores paths specified in .terraformignore
)
if err != nil {
log.Fatal(err)
Expand Down
57 changes: 57 additions & 0 deletions examples/projects/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package main

import (
"context"
"log"

tfe "github.com/hashicorp/go-tfe"

"github.com/hashicorp/jsonapi"
)

func main() {
config := &tfe.Config{
Token: "insert-your-token-here",
RetryServerErrors: true,
}

client, err := tfe.NewClient(config)
if err != nil {
log.Fatal(err)
}

// Create a context
ctx := context.Background()

// Create a new project
p, err := client.Projects.Create(ctx, "org-test", tfe.ProjectCreateOptions{
Name: "my-app-tst",
})
if err != nil {
log.Fatal(err)
}

// Update the project auto destroy activity duration
p, err = client.Projects.Update(ctx, p.ID, tfe.ProjectUpdateOptions{
AutoDestroyActivityDuration: jsonapi.NewNullableAttrWithValue("3d"),
})
if err != nil {
log.Fatal(err)
}

// Disable auto destroy
p, err = client.Projects.Update(ctx, p.ID, tfe.ProjectUpdateOptions{
AutoDestroyActivityDuration: jsonapi.NewNullNullableAttr[string](),
})
if err != nil {
log.Fatal(err)
}

err = client.Projects.Delete(ctx, p.ID)
if err != nil {
log.Fatal(err)
}
}
Loading

0 comments on commit 1219fe5

Please sign in to comment.