forked from hashicorp/terraform-provider-tfe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workspace): add auto destroy attribute to resource and data sour…
…ce (hashicorp#1354) * feat(workspace): add auto destroy attribute to resource and data source This change adds `auto_destroy_at` to Workspace resource and data source schemas. The Workspaces API accepts three possible types of values for auto_destroy_at: - a set value - e.g. a payload with the shape `{ "data": { "attributes": { "name": "some-workspace", "auto-destroy-at": "2006-01-02T15:04:05Z" }}}` - an ignored value - e.g. a payload with the shape `{ "data": { "attributes": { "name": "some-workspace" }}}` - and an unset value - e.g. a payload with the shape `{ "data": { "attributes": { "name": "some-workspace", "auto-destroy-at": null }}}` * standardize auto destroy error messages * fix changelog * add docs note for `auto_destroy_at` attribute * update docs * call out ignore_changes for workspace auto destroy docs
- Loading branch information
1 parent
1d447dd
commit 5219dbf
Showing
7 changed files
with
195 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,25 @@ func TestAccTFEWorkspaceDataSourceWithTriggerPatterns(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccTFEWorkspaceDataSource_readAutoDestroyAt(t *testing.T) { | ||
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccTFEWorkspaceDataSourceConfig_basic(rInt), | ||
Check: resource.TestCheckResourceAttr("data.tfe_workspace.foobar", "auto_destroy_at", ""), | ||
}, | ||
{ | ||
Config: testAccTFEWorkspaceDataSourceConfig_basicWithAutoDestroy(rInt), | ||
Check: resource.TestCheckResourceAttr("data.tfe_workspace.foobar", "auto_destroy_at", "2100-01-01T00:00:00Z"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccTFEWorkspaceDataSource_readProjectIDDefault(t *testing.T) { | ||
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int() | ||
|
||
|
@@ -243,6 +262,44 @@ data "tfe_workspace" "foobar" { | |
}`, rInt, rInt, aart) | ||
} | ||
|
||
func testAccTFEWorkspaceDataSourceConfig_basic(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "tfe_organization" "foobar" { | ||
name = "tst-terraform-%d" | ||
email = "[email protected]" | ||
} | ||
resource "tfe_workspace" "foobar" { | ||
name = "workspace-test-%d" | ||
organization = tfe_organization.foobar.id | ||
description = "provider-testing" | ||
} | ||
data "tfe_workspace" "foobar" { | ||
name = tfe_workspace.foobar.name | ||
organization = tfe_workspace.foobar.organization | ||
}`, rInt, rInt) | ||
} | ||
|
||
func testAccTFEWorkspaceDataSourceConfig_basicWithAutoDestroy(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "tfe_organization" "foobar" { | ||
name = "tst-terraform-%d" | ||
email = "[email protected]" | ||
} | ||
resource "tfe_workspace" "foobar" { | ||
name = "workspace-test-%d" | ||
organization = tfe_organization.foobar.id | ||
description = "provider-testing" | ||
auto_destroy_at = "2100-01-01T00:00:00Z" | ||
} | ||
data "tfe_workspace" "foobar" { | ||
name = tfe_workspace.foobar.name | ||
organization = tfe_workspace.foobar.organization | ||
}`, rInt, rInt) | ||
} | ||
func testAccTFEWorkspaceDataSourceConfigWithTriggerPatterns(workspaceName string, organizationName string) string { | ||
return fmt.Sprintf(` | ||
data "tfe_workspace" "foobar" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2648,6 +2648,52 @@ func TestAccTFEWorkspace_basicAssessmentsEnabled(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccTFEWorkspace_createWithAutoDestroyAt(t *testing.T) { | ||
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckTFEWorkspaceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccTFEWorkspace_basicWithAutoDestroyAt(rInt), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckTFEWorkspaceExists("tfe_workspace.foobar", &tfe.Workspace{}, testAccProvider), | ||
resource.TestCheckResourceAttr("tfe_workspace.foobar", "auto_destroy_at", "2100-01-01T00:00:00Z"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccTFEWorkspace_updateWithAutoDestroyAt(t *testing.T) { | ||
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckTFEWorkspaceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccTFEWorkspace_basic(rInt), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckTFEWorkspaceExists("tfe_workspace.foobar", &tfe.Workspace{}, testAccProvider), | ||
resource.TestCheckResourceAttr("tfe_workspace.foobar", "auto_destroy_at", ""), | ||
), | ||
}, | ||
{ | ||
Config: testAccTFEWorkspace_basicWithAutoDestroyAt(rInt), | ||
Check: resource.TestCheckResourceAttr("tfe_workspace.foobar", "auto_destroy_at", "2100-01-01T00:00:00Z"), | ||
}, | ||
{ | ||
Config: testAccTFEWorkspace_basic(rInt), | ||
Check: resource.TestCheckResourceAttr("tfe_workspace.foobar", "auto_destroy_at", ""), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccTFEWorkspace_createWithSourceURL(t *testing.T) { | ||
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int() | ||
|
||
|
@@ -2924,6 +2970,22 @@ resource "tfe_workspace" "foobar" { | |
}`, rInt) | ||
} | ||
|
||
func testAccTFEWorkspace_basicWithAutoDestroyAt(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "tfe_organization" "foobar" { | ||
name = "tst-terraform-%d" | ||
email = "[email protected]" | ||
} | ||
resource "tfe_workspace" "foobar" { | ||
name = "workspace-test" | ||
organization = tfe_organization.foobar.id | ||
auto_apply = true | ||
file_triggers_enabled = false | ||
auto_destroy_at = "2100-01-01T00:00:00Z" | ||
}`, rInt) | ||
} | ||
|
||
func testAccTFEWorkspace_operationsTrue(organization string) string { | ||
return fmt.Sprintf(` | ||
resource "tfe_workspace" "foobar" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters