Skip to content

Commit

Permalink
Merge pull request #798 from hashicorp/nf/oct23-auto-run-trigger
Browse files Browse the repository at this point in the history
Add AutoApplyRunTrigger attribute to workspaces
  • Loading branch information
nfagerlund authored Nov 7, 2023
2 parents 8bd669d + d9f7d45 commit 3e993c6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
## Features
* New WorkspaceSettingOverwritesOptions field for allowing workspaces to defer some settings to a default from their organization or project by @SwiftEngineer [#762](https://github.com/hashicorp/go-tfe/pull/762)
* Added support for setting a default execution mode and agent pool at the organization level by @SwiftEngineer [#762](https://github.com/hashicorp/go-tfe/pull/762)

## Features
* Removed BETA labels for StateVersion Upload method, ConfigurationVersion `provisional` field, and `save-plan` runs by @brandonc [#800](https://github.com/hashicorp/go-tfe/pull/800)
* Allow soft deleting, restoring, and permanently deleting StateVersion and ConfigurationVersion backing data by @mwudka [#801](https://github.com/hashicorp/go-tfe/pull/801)
* Added the `AutoApplyRunTrigger` attribute to Workspaces by @nfagerlund [#798](https://github.com/hashicorp/go-tfe/pull/798)

# v.1.38.0

Expand Down
9 changes: 9 additions & 0 deletions workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ type Workspace struct {
AllowDestroyPlan bool `jsonapi:"attr,allow-destroy-plan"`
AssessmentsEnabled bool `jsonapi:"attr,assessments-enabled"`
AutoApply bool `jsonapi:"attr,auto-apply"`
AutoApplyRunTrigger bool `jsonapi:"attr,auto-apply-run-trigger"`
CanQueueDestroyPlan bool `jsonapi:"attr,can-queue-destroy-plan"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
Description string `jsonapi:"attr,description"`
Expand Down Expand Up @@ -305,6 +306,10 @@ type WorkspaceCreateOptions struct {
// Optional: Whether to automatically apply changes when a Terraform plan is successful.
AutoApply *bool `jsonapi:"attr,auto-apply,omitempty"`

// Optional: Whether to automatically apply changes for runs that are created by run triggers
// from another workspace.
AutoApplyRunTrigger *bool `jsonapi:"attr,auto-apply-run-trigger,omitempty"`

// Optional: A description for the workspace.
Description *string `jsonapi:"attr,description,omitempty"`

Expand Down Expand Up @@ -448,6 +453,10 @@ type WorkspaceUpdateOptions struct {
// Optional: Whether to automatically apply changes when a Terraform plan is successful.
AutoApply *bool `jsonapi:"attr,auto-apply,omitempty"`

// Optional: Whether to automatically apply changes for runs that are created by run triggers
// from another workspace.
AutoApplyRunTrigger *bool `jsonapi:"attr,auto-apply-run-trigger,omitempty"`

// Optional: A new name for the workspace, which can only include letters, numbers, -,
// and _. This will be used as an identifier and must be unique in the
// organization. Warning: Changing a workspace's name changes its URL in the
Expand Down
47 changes: 45 additions & 2 deletions workspace_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,37 @@ func TestWorkspacesCreate(t *testing.T) {
}
})

t.Run("with valid auto-apply-run-trigger option", func(t *testing.T) {
skipIfEnterprise(t)
// FEATURE FLAG: auto-apply-run-trigger
// Once un-flagged, delete this test and add an AutoApplyRunTrigger field
// to the basic "with valid options" test below.

options := WorkspaceCreateOptions{
Name: String(fmt.Sprintf("foo-%s", randomString(t))),
AutoApplyRunTrigger: Bool(true),
}

w, err := client.Workspaces.Create(ctx, orgTest.Name, options)
require.NoError(t, err)

// Get a refreshed view from the API.
refreshed, err := client.Workspaces.Read(ctx, orgTest.Name, *options.Name)
require.NoError(t, err)

for _, item := range []*Workspace{
w,
refreshed,
} {
assert.NotEmpty(t, item.ID)
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, *options.AutoApplyRunTrigger, item.AutoApplyRunTrigger)
}
})

t.Run("with valid options", func(t *testing.T) {
options := WorkspaceCreateOptions{
Name: String("foo"),
Name: String(fmt.Sprintf("foo-%s", randomString(t))),
AllowDestroyPlan: Bool(false),
AutoApply: Bool(true),
Description: String("qux"),
Expand Down Expand Up @@ -581,7 +609,7 @@ func TestWorkspacesCreate(t *testing.T) {

t.Run("when options has an invalid organization", func(t *testing.T) {
w, err := client.Workspaces.Create(ctx, badIdentifier, WorkspaceCreateOptions{
Name: String("foo"),
Name: String(fmt.Sprintf("foo-%s", randomString(t))),
})
assert.Nil(t, w)
assert.EqualError(t, err, ErrInvalidOrg.Error())
Expand Down Expand Up @@ -1043,6 +1071,21 @@ func TestWorkspacesUpdate(t *testing.T) {
assert.Equal(t, wTest.WorkingDirectory, wAfter.WorkingDirectory)
})

t.Run("when updating auto-apply-run-trigger", func(t *testing.T) {
skipIfEnterprise(t)
// Feature flag: auto-apply-run-trigger. Once flag is removed, delete
// this test and add the attribute to one generic update test.
options := WorkspaceUpdateOptions{
AutoApplyRunTrigger: Bool(true),
}

wAfter, err := client.Workspaces.Update(ctx, orgTest.Name, wTest.Name, options)
require.NoError(t, err)

assert.Equal(t, wTest.Name, wAfter.Name)
assert.NotEqual(t, wTest.AutoApplyRunTrigger, wAfter.AutoApplyRunTrigger)
})

t.Run("when updating project", func(t *testing.T) {
skipUnlessBeta(t)

Expand Down

0 comments on commit 3e993c6

Please sign in to comment.