Skip to content

Commit 5d0d321

Browse files
authored
Merged automatically by CI pipeline
SCALRCORE-25441 Deletion protection
2 parents 9bc6442 + 284b0e3 commit 5d0d321

File tree

2 files changed

+58
-45
lines changed

2 files changed

+58
-45
lines changed

workspace.go

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,30 @@ type WorkspaceList struct {
6767

6868
// Workspace represents a Scalr workspace.
6969
type Workspace struct {
70-
ID string `jsonapi:"primary,workspaces"`
71-
Actions *WorkspaceActions `jsonapi:"attr,actions"`
72-
AutoApply bool `jsonapi:"attr,auto-apply"`
73-
ForceLatestRun bool `jsonapi:"attr,force-latest-run"`
74-
CanQueueDestroyPlan bool `jsonapi:"attr,can-queue-destroy-plan"`
75-
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
76-
FileTriggersEnabled bool `jsonapi:"attr,file-triggers-enabled"`
77-
Locked bool `jsonapi:"attr,locked"`
78-
MigrationEnvironment string `jsonapi:"attr,migration-environment"`
79-
Name string `jsonapi:"attr,name"`
80-
Operations bool `jsonapi:"attr,operations"`
81-
ExecutionMode WorkspaceExecutionMode `jsonapi:"attr,execution-mode"`
82-
Permissions *WorkspacePermissions `jsonapi:"attr,permissions"`
83-
TerraformVersion string `jsonapi:"attr,terraform-version"`
84-
VCSRepo *WorkspaceVCSRepo `jsonapi:"attr,vcs-repo"`
85-
WorkingDirectory string `jsonapi:"attr,working-directory"`
86-
ApplySchedule string `jsonapi:"attr,apply-schedule"`
87-
DestroySchedule string `jsonapi:"attr,destroy-schedule"`
88-
HasResources bool `jsonapi:"attr,has-resources"`
89-
AutoQueueRuns WorkspaceAutoQueueRuns `jsonapi:"attr,auto-queue-runs"`
90-
Hooks *Hooks `jsonapi:"attr,hooks"`
91-
RunOperationTimeout *int `jsonapi:"attr,run-operation-timeout"`
92-
VarFiles []string `jsonapi:"attr,var-files"`
70+
ID string `jsonapi:"primary,workspaces"`
71+
Actions *WorkspaceActions `jsonapi:"attr,actions"`
72+
AutoApply bool `jsonapi:"attr,auto-apply"`
73+
ForceLatestRun bool `jsonapi:"attr,force-latest-run"`
74+
DeletionProtectionEnabled bool `jsonapi:"attr,deletion-protection-enabled"`
75+
CanQueueDestroyPlan bool `jsonapi:"attr,can-queue-destroy-plan"`
76+
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
77+
FileTriggersEnabled bool `jsonapi:"attr,file-triggers-enabled"`
78+
Locked bool `jsonapi:"attr,locked"`
79+
MigrationEnvironment string `jsonapi:"attr,migration-environment"`
80+
Name string `jsonapi:"attr,name"`
81+
Operations bool `jsonapi:"attr,operations"`
82+
ExecutionMode WorkspaceExecutionMode `jsonapi:"attr,execution-mode"`
83+
Permissions *WorkspacePermissions `jsonapi:"attr,permissions"`
84+
TerraformVersion string `jsonapi:"attr,terraform-version"`
85+
VCSRepo *WorkspaceVCSRepo `jsonapi:"attr,vcs-repo"`
86+
WorkingDirectory string `jsonapi:"attr,working-directory"`
87+
ApplySchedule string `jsonapi:"attr,apply-schedule"`
88+
DestroySchedule string `jsonapi:"attr,destroy-schedule"`
89+
HasResources bool `jsonapi:"attr,has-resources"`
90+
AutoQueueRuns WorkspaceAutoQueueRuns `jsonapi:"attr,auto-queue-runs"`
91+
Hooks *Hooks `jsonapi:"attr,hooks"`
92+
RunOperationTimeout *int `jsonapi:"attr,run-operation-timeout"`
93+
VarFiles []string `jsonapi:"attr,var-files"`
9394

9495
// Relations
9596
CurrentRun *Run `jsonapi:"relation,current-run"`
@@ -189,6 +190,9 @@ type WorkspaceCreateOptions struct {
189190
// Whether to automatically raise the priority of the latest new run.
190191
ForceLatestRun *bool `jsonapi:"attr,force-latest-run,omitempty"`
191192

193+
// Whether to prevent deletion when the workspace has resources.
194+
DeletionProtectionEnabled *bool `jsonapi:"attr,deletion-protection-enabled,omitempty"`
195+
192196
// The name of the workspace, which can only include letters, numbers, -,
193197
// and _. This will be used as an identifier and must be unique in the
194198
// environment.
@@ -360,6 +364,9 @@ type WorkspaceUpdateOptions struct {
360364
// Whether to automatically raise the priority of the latest new run.
361365
ForceLatestRun *bool `jsonapi:"attr,force-latest-run,omitempty"`
362366

367+
// Whether to prevent deletion when the workspace has resources.
368+
DeletionProtectionEnabled *bool `jsonapi:"attr,deletion-protection-enabled,omitempty"`
369+
363370
// A new name for the workspace, which can only include letters, numbers, -,
364371
// and _. This will be used as an identifier and must be unique in the
365372
// environment. Warning: Changing a workspace's name changes its URL in the

workspace_test.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,16 @@ func TestWorkspacesCreate(t *testing.T) {
9595

9696
t.Run("with valid options", func(t *testing.T) {
9797
options := WorkspaceCreateOptions{
98-
Environment: envTest,
99-
Name: String(randomString(t)),
100-
AutoApply: Bool(true),
101-
ForceLatestRun: Bool(true),
102-
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeRemote),
103-
TerraformVersion: String("1.1.9"),
104-
WorkingDirectory: String("bar/"),
105-
RunOperationTimeout: Int(15),
106-
AutoQueueRuns: AutoQueueRunsModePtr(AutoQueueRunsModeNever),
98+
Environment: envTest,
99+
Name: String(randomString(t)),
100+
AutoApply: Bool(true),
101+
ForceLatestRun: Bool(true),
102+
DeletionProtectionEnabled: Bool(false),
103+
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeRemote),
104+
TerraformVersion: String("1.1.9"),
105+
WorkingDirectory: String("bar/"),
106+
RunOperationTimeout: Int(15),
107+
AutoQueueRuns: AutoQueueRunsModePtr(AutoQueueRunsModeNever),
107108
}
108109

109110
ws, err := client.Workspaces.Create(ctx, options)
@@ -121,6 +122,7 @@ func TestWorkspacesCreate(t *testing.T) {
121122
assert.Equal(t, *options.Name, item.Name)
122123
assert.Equal(t, *options.AutoApply, item.AutoApply)
123124
assert.Equal(t, *options.ForceLatestRun, item.ForceLatestRun)
125+
assert.Equal(t, *options.DeletionProtectionEnabled, item.DeletionProtectionEnabled)
124126
assert.Equal(t, false, item.HasResources)
125127
assert.Equal(t, *options.ExecutionMode, item.ExecutionMode)
126128
assert.Equal(t, *options.TerraformVersion, item.TerraformVersion)
@@ -295,13 +297,14 @@ func TestWorkspacesUpdate(t *testing.T) {
295297

296298
t.Run("when updating a subset of values", func(t *testing.T) {
297299
options := WorkspaceUpdateOptions{
298-
Name: String(wsTest.Name),
299-
AutoApply: Bool(true),
300-
ForceLatestRun: Bool(true),
301-
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeRemote),
302-
TerraformVersion: String("1.2.9"),
303-
RunOperationTimeout: Int(20),
304-
AutoQueueRuns: AutoQueueRunsModePtr(AutoQueueRunsModeAlways),
300+
Name: String(wsTest.Name),
301+
AutoApply: Bool(true),
302+
ForceLatestRun: Bool(true),
303+
DeletionProtectionEnabled: Bool(false),
304+
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeRemote),
305+
TerraformVersion: String("1.2.9"),
306+
RunOperationTimeout: Int(20),
307+
AutoQueueRuns: AutoQueueRunsModePtr(AutoQueueRunsModeAlways),
305308
}
306309

307310
wsAfter, err := client.Workspaces.Update(ctx, wsTest.ID, options)
@@ -312,6 +315,7 @@ func TestWorkspacesUpdate(t *testing.T) {
312315
assert.Equal(t, *options.AutoQueueRuns, wsAfter.AutoQueueRuns)
313316
assert.NotEqual(t, wsTest.AutoApply, wsAfter.AutoApply)
314317
assert.NotEqual(t, wsTest.ForceLatestRun, wsAfter.ForceLatestRun)
318+
assert.NotEqual(t, wsTest.DeletionProtectionEnabled, wsAfter.DeletionProtectionEnabled)
315319
assert.NotEqual(t, wsTest.TerraformVersion, wsAfter.TerraformVersion)
316320
assert.Equal(t, wsTest.WorkingDirectory, wsAfter.WorkingDirectory)
317321
assert.Equal(t, int(20), *wsAfter.RunOperationTimeout)
@@ -340,12 +344,13 @@ func TestWorkspacesUpdate(t *testing.T) {
340344

341345
t.Run("with valid options", func(t *testing.T) {
342346
options := WorkspaceUpdateOptions{
343-
Name: String(randomString(t)),
344-
AutoApply: Bool(false),
345-
ForceLatestRun: Bool(false),
346-
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeLocal),
347-
TerraformVersion: String("1.1.9"),
348-
WorkingDirectory: String("baz/"),
347+
Name: String(randomString(t)),
348+
AutoApply: Bool(false),
349+
ForceLatestRun: Bool(false),
350+
DeletionProtectionEnabled: Bool(false),
351+
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeLocal),
352+
TerraformVersion: String("1.1.9"),
353+
WorkingDirectory: String("baz/"),
349354
}
350355

351356
w, err := client.Workspaces.Update(ctx, wsTest.ID, options)
@@ -362,6 +367,7 @@ func TestWorkspacesUpdate(t *testing.T) {
362367
assert.Equal(t, *options.Name, item.Name)
363368
assert.Equal(t, *options.AutoApply, item.AutoApply)
364369
assert.Equal(t, *options.ForceLatestRun, item.ForceLatestRun)
370+
assert.Equal(t, *options.DeletionProtectionEnabled, item.DeletionProtectionEnabled)
365371
assert.Equal(t, *options.ExecutionMode, item.ExecutionMode)
366372
assert.Equal(t, *options.TerraformVersion, item.TerraformVersion)
367373
assert.Equal(t, *options.WorkingDirectory, item.WorkingDirectory)

0 commit comments

Comments
 (0)