Skip to content

Commit

Permalink
Support Workspace allow-destroy-plan attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisarcand committed Nov 20, 2020
1 parent 87d99d2 commit 9522ea8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type Workspace struct {
ID string `jsonapi:"primary,workspaces"`
Actions *WorkspaceActions `jsonapi:"attr,actions"`
AgentPoolID string `jsonapi:"attr,agent-pool-id"`
AllowDestroyPlan bool `jsonapi:"attr,allow-destroy-plan"`
AutoApply bool `jsonapi:"attr,auto-apply"`
CanQueueDestroyPlan bool `jsonapi:"attr,can-queue-destroy-plan"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
Expand Down Expand Up @@ -173,6 +174,9 @@ type WorkspaceCreateOptions struct {
// if execution-mode is set to remote or local or if operations is set to true.
AgentPoolID *string `jsonapi:"attr,agent-pool-id,omitempty"`

// Whether destroy plans can be queued on the workspace.
AllowDestroyPlan *bool `jsonapi:"attr,allow-destroy-plan,omitempty"`

// Whether to automatically apply changes when a Terraform plan is successful.
AutoApply *bool `jsonapi:"attr,auto-apply,omitempty"`

Expand Down Expand Up @@ -346,6 +350,9 @@ type WorkspaceUpdateOptions struct {
// if execution-mode is set to remote or local or if operations is set to true.
AgentPoolID *string `jsonapi:"attr,agent-pool-id,omitempty"`

// Whether destroy plans can be queued on the workspace.
AllowDestroyPlan *bool `jsonapi:"attr,allow-destroy-plan,omitempty"`

// Whether to automatically apply changes when a Terraform plan is successful.
AutoApply *bool `jsonapi:"attr,auto-apply,omitempty"`

Expand Down
10 changes: 10 additions & 0 deletions workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func TestWorkspacesCreate(t *testing.T) {
t.Run("with valid options", func(t *testing.T) {
options := WorkspaceCreateOptions{
Name: String("foo"),
AllowDestroyPlan: Bool(false),
AutoApply: Bool(true),
FileTriggersEnabled: Bool(true),
Operations: Bool(true),
Expand All @@ -122,6 +123,7 @@ func TestWorkspacesCreate(t *testing.T) {
} {
assert.NotEmpty(t, item.ID)
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, *options.AllowDestroyPlan, item.AllowDestroyPlan)
assert.Equal(t, *options.AutoApply, item.AutoApply)
assert.Equal(t, *options.FileTriggersEnabled, item.FileTriggersEnabled)
assert.Equal(t, *options.Operations, item.Operations)
Expand Down Expand Up @@ -305,6 +307,7 @@ func TestWorkspacesUpdate(t *testing.T) {
t.Run("when updating a subset of values", func(t *testing.T) {
options := WorkspaceUpdateOptions{
Name: String(wTest.Name),
AllowDestroyPlan: Bool(false),
AutoApply: Bool(true),
Operations: Bool(true),
QueueAllRuns: Bool(true),
Expand All @@ -315,6 +318,7 @@ func TestWorkspacesUpdate(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, wTest.Name, wAfter.Name)
assert.NotEqual(t, wTest.AllowDestroyPlan, wAfter.AllowDestroyPlan)
assert.NotEqual(t, wTest.AutoApply, wAfter.AutoApply)
assert.NotEqual(t, wTest.QueueAllRuns, wAfter.QueueAllRuns)
assert.NotEqual(t, wTest.TerraformVersion, wAfter.TerraformVersion)
Expand All @@ -324,6 +328,7 @@ func TestWorkspacesUpdate(t *testing.T) {
t.Run("with valid options", func(t *testing.T) {
options := WorkspaceUpdateOptions{
Name: String(randomString(t)),
AllowDestroyPlan: Bool(true),
AutoApply: Bool(false),
FileTriggersEnabled: Bool(true),
Operations: Bool(false),
Expand All @@ -346,6 +351,7 @@ func TestWorkspacesUpdate(t *testing.T) {
refreshed,
} {
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, *options.AllowDestroyPlan, item.AllowDestroyPlan)
assert.Equal(t, *options.AutoApply, item.AutoApply)
assert.Equal(t, *options.FileTriggersEnabled, item.FileTriggersEnabled)
assert.Equal(t, *options.Operations, item.Operations)
Expand Down Expand Up @@ -411,6 +417,7 @@ func TestWorkspacesUpdateByID(t *testing.T) {
t.Run("when updating a subset of values", func(t *testing.T) {
options := WorkspaceUpdateOptions{
Name: String(wTest.Name),
AllowDestroyPlan: Bool(false),
AutoApply: Bool(true),
Operations: Bool(true),
QueueAllRuns: Bool(true),
Expand All @@ -421,6 +428,7 @@ func TestWorkspacesUpdateByID(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, wTest.Name, wAfter.Name)
assert.NotEqual(t, wTest.AllowDestroyPlan, wAfter.AllowDestroyPlan)
assert.NotEqual(t, wTest.AutoApply, wAfter.AutoApply)
assert.NotEqual(t, wTest.QueueAllRuns, wAfter.QueueAllRuns)
assert.NotEqual(t, wTest.TerraformVersion, wAfter.TerraformVersion)
Expand All @@ -430,6 +438,7 @@ func TestWorkspacesUpdateByID(t *testing.T) {
t.Run("with valid options", func(t *testing.T) {
options := WorkspaceUpdateOptions{
Name: String(randomString(t)),
AllowDestroyPlan: Bool(true),
AutoApply: Bool(false),
FileTriggersEnabled: Bool(true),
Operations: Bool(false),
Expand All @@ -452,6 +461,7 @@ func TestWorkspacesUpdateByID(t *testing.T) {
refreshed,
} {
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, *options.AllowDestroyPlan, item.AllowDestroyPlan)
assert.Equal(t, *options.AutoApply, item.AutoApply)
assert.Equal(t, *options.FileTriggersEnabled, item.FileTriggersEnabled)
assert.Equal(t, *options.Operations, item.Operations)
Expand Down

0 comments on commit 9522ea8

Please sign in to comment.