Skip to content

Commit

Permalink
Add AutoApplyRunTrigger attribute to workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nfagerlund committed Nov 1, 2023
1 parent c8c9b27 commit c593200
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
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 @@ -297,6 +298,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"`

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

Expand Down Expand Up @@ -420,6 +425,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"`

// 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
43 changes: 43 additions & 0 deletions workspace_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,34 @@ func TestWorkspacesCreate(t *testing.T) {
}
})

t.Run("with valid auto-apply-run-trigger option", func(t *testing.T) {
skipUnlessBeta(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("foo"),
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"),
Expand Down Expand Up @@ -944,6 +972,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) {
skipUnlessBeta(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 c593200

Please sign in to comment.