Skip to content

Commit

Permalink
[TF-9914] Add auto destroy to workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
notchairmk committed Oct 9, 2023
1 parent 0f378a3 commit 484fbd7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<!-- Add CHANGELOG entry to this section for any PR awaiting the next release -->
<!-- Please also include if this is a Bug Fix, Enhancement, or Feature -->

## Enhancements
* Updates `Workspaces` to include an `AutoDestroyAt` attribute on create and update by @notchairmk [#786](https://github.com/hashicorp/go-tfe/pull/786)

# v.1.35.0
## Features
* Added BETA support for private module registry tests by @hashimoon [#781](https://github.com/hashicorp/go-tfe/pull/781)
Expand Down
7 changes: 7 additions & 0 deletions type_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package tfe

import "time"

// Access returns a pointer to the given team access type.
func Access(v AccessType) *AccessType {
return &v
Expand Down Expand Up @@ -78,6 +80,11 @@ func Category(v CategoryType) *CategoryType {
return &v
}

// Time returns a pointer to the given time
func Time(v time.Time) *time.Time {
return &v
}

// EnforcementMode returns a pointer to the given enforcement level.
func EnforcementMode(v EnforcementLevel) *EnforcementLevel {
return &v
Expand Down
7 changes: 7 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"`
AutoDestroyAt *time.Time `jsonapi:"attr,auto-destroy-at,iso8601"`
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 @@ -296,6 +297,9 @@ type WorkspaceCreateOptions struct {
// Optional: Whether to automatically apply changes when a Terraform plan is successful.
AutoApply *bool `jsonapi:"attr,auto-apply,omitempty"`

// Optional: The time after which an automatic destroy run will be queued
AutoDestroyAt *time.Time `jsonapi:"attr,auto-destroy-at,iso8601,omitempty"`

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

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

// Optional: The time after which an automatic destroy run will be queued
AutoDestroyAt *time.Time `jsonapi:"attr,auto-destroy-at,iso8601,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
6 changes: 5 additions & 1 deletion workspace_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,9 @@ func TestWorkspacesCreate(t *testing.T) {
t.Run("with valid options", func(t *testing.T) {
options := WorkspaceCreateOptions{
Name: String("foo"),
AllowDestroyPlan: Bool(false),
AllowDestroyPlan: Bool(true),
AutoApply: Bool(true),
AutoDestroyAt: Time(time.Date(2024, 1, 15, 22, 3, 4, 0, time.UTC)),
Description: String("qux"),
AssessmentsEnabled: Bool(false),
FileTriggersEnabled: Bool(true),
Expand Down Expand Up @@ -549,6 +550,7 @@ func TestWorkspacesCreate(t *testing.T) {
assert.Equal(t, *options.Description, item.Description)
assert.Equal(t, *options.AllowDestroyPlan, item.AllowDestroyPlan)
assert.Equal(t, *options.AutoApply, item.AutoApply)
assert.Equal(t, options.AutoDestroyAt, item.AutoDestroyAt)
assert.Equal(t, *options.AssessmentsEnabled, item.AssessmentsEnabled)
assert.Equal(t, *options.FileTriggersEnabled, item.FileTriggersEnabled)
assert.Equal(t, *options.Operations, item.Operations)
Expand Down Expand Up @@ -982,6 +984,7 @@ func TestWorkspacesUpdate(t *testing.T) {
Name: String(randomString(t)),
AllowDestroyPlan: Bool(true),
AutoApply: Bool(false),
AutoDestroyAt: Time(time.Date(2024, 1, 15, 22, 3, 4, 0, time.UTC)),
FileTriggersEnabled: Bool(true),
Operations: Bool(false),
QueueAllRuns: Bool(false),
Expand All @@ -1007,6 +1010,7 @@ func TestWorkspacesUpdate(t *testing.T) {
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.AutoDestroyAt, item.AutoDestroyAt)
assert.Equal(t, *options.FileTriggersEnabled, item.FileTriggersEnabled)
assert.Equal(t, *options.Description, item.Description)
assert.Equal(t, *options.Operations, item.Operations)
Expand Down

0 comments on commit 484fbd7

Please sign in to comment.