Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/hashicorp/g…
Browse files Browse the repository at this point in the history
…o-version-1.7.0
  • Loading branch information
brandonc authored Aug 5, 2024
2 parents 873d5d9 + 217b7bf commit 7857459
Show file tree
Hide file tree
Showing 30 changed files with 1,471 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.github/ @hashicorp/tf-cli
Makefile @hashicorp/tf-cli
1 change: 1 addition & 0 deletions .github/actions/test-go-tfe/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ runs:
TFC_RUN_TASK_URL: "http://testing-mocks.tfe:22180/runtasks/pass"
GITHUB_POLICY_SET_IDENTIFIER: "hashicorp/test-policy-set"
GITHUB_REGISTRY_MODULE_IDENTIFIER: "hashicorp/terraform-random-module"
GITHUB_REGISTRY_NO_CODE_MODULE_IDENTIFIER: "hashicorp/terraform-random-no-code-module"
OAUTH_CLIENT_GITHUB_TOKEN: "${{ inputs.oauth-client-github-token }}"
GO111MODULE: "on"
ENABLE_TFE: ${{ inputs.enterprise }}
Expand Down
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
# UNRELEASED
* Adds `AllowMemberTokenManagement` permission to `Team` by @juliannatetreault [#922](https://github.com/hashicorp/go-tfe/pull/922)

# v1.61.0

## Enhancements

* Adds support for creating no-code workspaces by @paladin-devops [#927](https://github.com/hashicorp/go-tfe/pull/927)
* Adds support for upgrading no-code workspaces by @paladin-devops [#935](https://github.com/hashicorp/go-tfe/pull/935)

# v1.60.0

## Enhancements

* Adds more BETA support for `Stacks` resources, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @brandonc. [#934](https://github.com/hashicorp/go-tfe/pull/934)

# v1.59.0

## Features

* Adds support for the Run Tasks Integration API by @karvounis-form3 [#929](https://github.com/hashicorp/go-tfe/pull/929)

# v1.58.0

## Enhancements

* Adds BETA support for `Stacks` resources, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users. [#920](https://github.com/hashicorp/go-tfe/pull/920)
* Adds BETA support for `Stacks` resources, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @brandonc. [#920](https://github.com/hashicorp/go-tfe/pull/920)

# v1.57.0

Expand Down
1 change: 0 additions & 1 deletion CODEOWNERS

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ This API client covers most of the existing HCP Terraform API calls and is updat
- [x] Runs
- [x] Run Events
- [x] Run Tasks
- [ ] Run Tasks Integration
- [x] Run Tasks Integration
- [x] Run Triggers
- [x] SSH Keys
- [x] Stability Policy
Expand Down
4 changes: 4 additions & 0 deletions admin_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type AdminOrganization struct {
SsoEnabled bool `jsonapi:"attr,sso-enabled"`
TerraformBuildWorkerApplyTimeout string `jsonapi:"attr,terraform-build-worker-apply-timeout"`
TerraformBuildWorkerPlanTimeout string `jsonapi:"attr,terraform-build-worker-plan-timeout"`
ApplyTimeout string `jsonapi:"attr,apply-timeout"`
PlanTimeout string `jsonapi:"attr,plan-timeout"`
TerraformWorkerSudoEnabled bool `jsonapi:"attr,terraform-worker-sudo-enabled"`
WorkspaceLimit *int `jsonapi:"attr,workspace-limit"`

Expand All @@ -69,6 +71,8 @@ type AdminOrganizationUpdateOptions struct {
IsDisabled *bool `jsonapi:"attr,is-disabled,omitempty"`
TerraformBuildWorkerApplyTimeout *string `jsonapi:"attr,terraform-build-worker-apply-timeout,omitempty"`
TerraformBuildWorkerPlanTimeout *string `jsonapi:"attr,terraform-build-worker-plan-timeout,omitempty"`
ApplyTimeout *string `jsonapi:"attr,apply-timeout,omitempty"`
PlanTimeout *string `jsonapi:"attr,plan-timeout,omitempty"`
TerraformWorkerSudoEnabled bool `jsonapi:"attr,terraform-worker-sudo-enabled,omitempty"`
WorkspaceLimit *int `jsonapi:"attr,workspace-limit,omitempty"`
}
Expand Down
16 changes: 10 additions & 6 deletions admin_organization_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,19 @@ func TestAdminOrganizations_Update(t *testing.T) {
globalModuleSharing := false
globalProviderSharing := false
isDisabled := false
terraformBuildWorkerApplyTimeout := "24h"
terraformBuildWorkerPlanTimeout := "24h"
applyTimeout := "24h"
planTimeout := "24h"
terraformWorkerSudoEnabled := true

opts := AdminOrganizationUpdateOptions{
AccessBetaTools: &accessBetaTools,
GlobalModuleSharing: &globalModuleSharing,
GlobalProviderSharing: &globalProviderSharing,
IsDisabled: &isDisabled,
TerraformBuildWorkerApplyTimeout: &terraformBuildWorkerApplyTimeout,
TerraformBuildWorkerPlanTimeout: &terraformBuildWorkerPlanTimeout,
TerraformBuildWorkerApplyTimeout: &applyTimeout,
TerraformBuildWorkerPlanTimeout: &planTimeout,
ApplyTimeout: &applyTimeout,
PlanTimeout: &planTimeout,
TerraformWorkerSudoEnabled: terraformWorkerSudoEnabled,
}

Expand All @@ -244,8 +246,10 @@ func TestAdminOrganizations_Update(t *testing.T) {
assert.Equal(t, adminOrg.GlobalModuleSharing, &globalModuleSharing)
assert.Equal(t, adminOrg.GlobalProviderSharing, &globalProviderSharing)
assert.Equal(t, isDisabled, adminOrg.IsDisabled)
assert.Equal(t, terraformBuildWorkerApplyTimeout, adminOrg.TerraformBuildWorkerApplyTimeout)
assert.Equal(t, terraformBuildWorkerPlanTimeout, adminOrg.TerraformBuildWorkerPlanTimeout)
assert.Equal(t, applyTimeout, adminOrg.TerraformBuildWorkerApplyTimeout)
assert.Equal(t, planTimeout, adminOrg.TerraformBuildWorkerPlanTimeout)
assert.Equal(t, applyTimeout, adminOrg.ApplyTimeout)
assert.Equal(t, planTimeout, adminOrg.PlanTimeout)
assert.Equal(t, terraformWorkerSudoEnabled, adminOrg.TerraformWorkerSudoEnabled)
assert.Nil(t, adminOrg.WorkspaceLimit, "default workspace limit should be nil")

Expand Down
16 changes: 10 additions & 6 deletions admin_setting_general.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,23 @@ type AdminGeneralSetting struct {
DefaultWorkspacesPerOrgCeiling int `jsonapi:"attr,default-workspaces-per-organization-ceiling"`
TerraformBuildWorkerApplyTimeout string `jsonapi:"attr,terraform-build-worker-apply-timeout"`
TerraformBuildWorkerPlanTimeout string `jsonapi:"attr,terraform-build-worker-plan-timeout"`
ApplyTimeout string `jsonapi:"attr,apply-timeout"`
PlanTimeout string `jsonapi:"attr,plan-timeout"`
DefaultRemoteStateAccess bool `jsonapi:"attr,default-remote-state-access"`
}

// AdminGeneralSettingsUpdateOptions represents the admin options for updating
// general settings.
// https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/settings#request-body
type AdminGeneralSettingsUpdateOptions struct {
LimitUserOrgCreation *bool `jsonapi:"attr,limit-user-organization-creation,omitempty"`
APIRateLimitingEnabled *bool `jsonapi:"attr,api-rate-limiting-enabled,omitempty"`
APIRateLimit *int `jsonapi:"attr,api-rate-limit,omitempty"`
SendPassingStatusUntriggeredPlans *bool `jsonapi:"attr,send-passing-statuses-for-untriggered-speculative-plans,omitempty"`
AllowSpeculativePlansOnPR *bool `jsonapi:"attr,allow-speculative-plans-on-pull-requests-from-forks,omitempty"`
DefaultRemoteStateAccess *bool `jsonapi:"attr,default-remote-state-access,omitempty"`
LimitUserOrgCreation *bool `jsonapi:"attr,limit-user-organization-creation,omitempty"`
APIRateLimitingEnabled *bool `jsonapi:"attr,api-rate-limiting-enabled,omitempty"`
APIRateLimit *int `jsonapi:"attr,api-rate-limit,omitempty"`
SendPassingStatusUntriggeredPlans *bool `jsonapi:"attr,send-passing-statuses-for-untriggered-speculative-plans,omitempty"`
AllowSpeculativePlansOnPR *bool `jsonapi:"attr,allow-speculative-plans-on-pull-requests-from-forks,omitempty"`
DefaultRemoteStateAccess *bool `jsonapi:"attr,default-remote-state-access,omitempty"`
ApplyTimeout *string `jsonapi:"attr,apply-timeout"`
PlanTimeout *string `jsonapi:"attr,plan-timeout"`
}

// Read returns the general settings.
Expand Down
14 changes: 14 additions & 0 deletions admin_setting_general_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func TestAdminSettings_General_Read(t *testing.T) {
assert.NotNil(t, generalSettings.DefaultWorkspacesPerOrgCeiling)
assert.NotNil(t, generalSettings.TerraformBuildWorkerApplyTimeout)
assert.NotNil(t, generalSettings.TerraformBuildWorkerPlanTimeout)
assert.NotNil(t, generalSettings.ApplyTimeout)
assert.NotNil(t, generalSettings.PlanTimeout)
assert.NotNil(t, generalSettings.DefaultRemoteStateAccess)
}

Expand All @@ -50,34 +52,46 @@ func TestAdminSettings_General_Update(t *testing.T) {
origAPIRateLimitEnabled := generalSettings.APIRateLimitingEnabled
origAPIRateLimit := generalSettings.APIRateLimit
origDefaultRemoteState := generalSettings.DefaultRemoteStateAccess
origApplyTimeout := generalSettings.ApplyTimeout
origPlanTimeout := generalSettings.PlanTimeout

limitOrgCreation := true
apiRateLimitEnabled := true
apiRateLimit := 50
defaultRemoteStateAccess := false
applyTimeout := "2h"
planTimeout := "30m"

generalSettings, err = client.Admin.Settings.General.Update(ctx, AdminGeneralSettingsUpdateOptions{
LimitUserOrgCreation: Bool(limitOrgCreation),
APIRateLimitingEnabled: Bool(apiRateLimitEnabled),
APIRateLimit: Int(apiRateLimit),
DefaultRemoteStateAccess: Bool(defaultRemoteStateAccess),
ApplyTimeout: &applyTimeout,
PlanTimeout: &planTimeout,
})
require.NoError(t, err)
assert.Equal(t, limitOrgCreation, generalSettings.LimitUserOrganizationCreation)
assert.Equal(t, apiRateLimitEnabled, generalSettings.APIRateLimitingEnabled)
assert.Equal(t, apiRateLimit, generalSettings.APIRateLimit)
assert.Equal(t, defaultRemoteStateAccess, generalSettings.DefaultRemoteStateAccess)
assert.Equal(t, applyTimeout, generalSettings.ApplyTimeout)
assert.Equal(t, planTimeout, generalSettings.PlanTimeout)

// Undo Updates, revert back to original
generalSettings, err = client.Admin.Settings.General.Update(ctx, AdminGeneralSettingsUpdateOptions{
LimitUserOrgCreation: Bool(origLimitOrgCreation),
APIRateLimitingEnabled: Bool(origAPIRateLimitEnabled),
APIRateLimit: Int(origAPIRateLimit),
DefaultRemoteStateAccess: Bool(origDefaultRemoteState),
ApplyTimeout: &origApplyTimeout,
PlanTimeout: &origPlanTimeout,
})
require.NoError(t, err)
assert.Equal(t, origLimitOrgCreation, generalSettings.LimitUserOrganizationCreation)
assert.Equal(t, origAPIRateLimitEnabled, generalSettings.APIRateLimitingEnabled)
assert.Equal(t, origAPIRateLimit, generalSettings.APIRateLimit)
assert.Equal(t, origDefaultRemoteState, generalSettings.DefaultRemoteStateAccess)
assert.Equal(t, origApplyTimeout, generalSettings.ApplyTimeout)
assert.Equal(t, origPlanTimeout, generalSettings.PlanTimeout)
}
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ There are instances where several new resources being added (i.e Workspace Run T

After opening a PR, our CI system will perform a series of code checks, one of which is linting. Linting is not strictly required for a change to be merged, but it helps smooth the review process and catch common mistakes early. If you'd like to run the linters manually, follow these steps:

1. Ensure you have [installed golangci-lint](https://golangci-lint.run/usage/install/#local-installation)
1. Ensure you have [installed golangci-lint](https://golangci-lint.run/welcome/install/#local-installation)
2. Format your code by running `make fmt`
3. Run lint checks using `make lint`

Expand Down
1 change: 1 addition & 0 deletions docs/TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Tests are run against an actual backend so they require a valid backend address
```sh
$ GITHUB_APP_INSTALLATION_ID=ghain-xxxx TFE_ADDRESS= https://tfe.local TFE_TOKEN=xxx GITHUB_POLICY_SET_IDENTIFIER=username/repository GITHUB_REGISTRY_MODULE_IDENTIFIER=username/repository go test -run "(GHA|GithubApp)" -v ./...
```
8. `GITHUB_REGISTRY_NO_CODE_MODULE_IDENTIFIER` - Required for running tests for workspaces using no-code modules.

## 3. Make sure run queue settings are correct

Expand Down
7 changes: 7 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package tfe

import (
"errors"
"fmt"
)

// Generic errors applicable to all resources.
Expand Down Expand Up @@ -219,6 +220,12 @@ var (
ErrInvalidModuleID = errors.New("invalid value for module ID")

ErrInvalidRegistryName = errors.New(`invalid value for registry-name. It must be either "private" or "public"`)

ErrInvalidCallbackURL = errors.New("invalid value for callback URL")

ErrInvalidAccessToken = errors.New("invalid value for access token")

ErrInvalidTaskResultsCallbackStatus = fmt.Errorf("invalid value for task result status. Must be either `%s`, `%s`, or `%s`", TaskFailed, TaskPassed, TaskRunning)
)

var (
Expand Down
23 changes: 23 additions & 0 deletions helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"io"
"math/rand"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path/filepath"
Expand All @@ -34,6 +35,8 @@ import (

const badIdentifier = "! / nope" //nolint
const agentVersion = "1.3.0"
const testInitialClientToken = "insert-your-token-here"
const testTaskResultCallbackToken = "this-is-task-result-callback-token"

var _testAccountDetails *TestAccountDetails

Expand Down Expand Up @@ -2855,6 +2858,26 @@ func requireExactlyOneNotEmpty(t *testing.T, v ...any) {
}
}

func runTaskCallbackMockServer(t *testing.T) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
return
}
if r.Header.Get("Accept") != ContentTypeJSONAPI {
t.Fatalf("unexpected accept header: %q", r.Header.Get("Accept"))
}
if r.Header.Get("Authorization") != fmt.Sprintf("Bearer %s", testTaskResultCallbackToken) {
t.Fatalf("unexpected authorization header: %q", r.Header.Get("Authorization"))
}
if r.Header.Get("Authorization") == fmt.Sprintf("Bearer %s", testInitialClientToken) {
t.Fatalf("authorization header is still the initial one: %q", r.Header.Get("Authorization"))
}
if r.Header.Get("User-Agent") != "go-tfe" {
t.Fatalf("unexpected user agent header: %q", r.Header.Get("User-Agent"))
}
}))
}

// Useless key but enough to pass validation in the API
const testGpgArmor string = `
-----BEGIN PGP PUBLIC KEY BLOCK-----
Expand Down
30 changes: 30 additions & 0 deletions mocks/registry_no_code_module_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7857459

Please sign in to comment.