-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(workspace): add auto destroy activity duration #1377
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6074f95
feat(workspace): add auto destroy activity duration
notchairmk 3b73392
revert custom diff interface
notchairmk 34c4695
fix duration data source setting state
notchairmk 6cdf1e6
Merge remote-tracking branch 'origin/main' into notchairmk/workspace-…
notchairmk f529b02
use validation helper, add tests
notchairmk 0ac6e4a
fix lint
notchairmk 6b66010
pr feedback
notchairmk dfc82e6
remove copied test
notchairmk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -190,6 +190,25 @@ func TestAccTFEWorkspaceDataSource_readAutoDestroyAt(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccTFEWorkspaceDataSource_readAutoDestroyDuration(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_activity_duration", ""), | ||
}, | ||
{ | ||
Config: testAccTFEWorkspaceDataSourceConfig_basicWithAutoDestroyDuration(rInt), | ||
Check: resource.TestCheckResourceAttr("data.tfe_workspace.foobar", "auto_destroy_activity_duration", "1d"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccTFEWorkspaceDataSource_readProjectIDDefault(t *testing.T) { | ||
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int() | ||
|
||
|
@@ -300,6 +319,27 @@ data "tfe_workspace" "foobar" { | |
organization = tfe_workspace.foobar.organization | ||
}`, rInt, rInt) | ||
} | ||
|
||
func testAccTFEWorkspaceDataSourceConfig_basicWithAutoDestroyDuration(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_activity_duration = "1d" | ||
} | ||
|
||
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 |
---|---|---|
|
@@ -2694,6 +2694,82 @@ func TestAccTFEWorkspace_updateWithAutoDestroyAt(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccTFEWorkspace_createWithAutoDestroyDuration(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_basicWithAutoDestroyDuration(rInt, "1d"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckTFEWorkspaceExists("tfe_workspace.foobar", &tfe.Workspace{}, testAccProvider), | ||
resource.TestCheckResourceAttr("tfe_workspace.foobar", "auto_destroy_activity_duration", "1d"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccTFEWorkspace_updateWithAutoDestroyDuration(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_basicWithAutoDestroyDuration(rInt, "1d"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckTFEWorkspaceExists("tfe_workspace.foobar", &tfe.Workspace{}, testAccProvider), | ||
resource.TestCheckResourceAttr("tfe_workspace.foobar", "auto_destroy_activity_duration", "1d"), | ||
), | ||
}, | ||
{ | ||
Config: testAccTFEWorkspace_basicWithAutoDestroyAt(rInt), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("tfe_workspace.foobar", "auto_destroy_activity_duration", ""), | ||
resource.TestCheckResourceAttr("tfe_workspace.foobar", "auto_destroy_at", "2100-01-01T00:00:00Z"), | ||
), | ||
}, | ||
{ | ||
Config: testAccTFEWorkspace_basicWithAutoDestroyDuration(rInt, "1d"), | ||
Check: resource.TestCheckResourceAttr("tfe_workspace.foobar", "auto_destroy_activity_duration", "1d"), | ||
}, | ||
{ | ||
Config: testAccTFEWorkspace_basic(rInt), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("tfe_workspace.foobar", "auto_destroy_at", ""), | ||
resource.TestCheckResourceAttr("tfe_workspace.foobar", "auto_destroy_activity_duration", ""), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccTFEWorkspace_validationAutoDestroyDuration(t *testing.T) { | ||
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int() | ||
|
||
values := []string{"d", "1w", "1d1", "123456h"} | ||
steps := []resource.TestStep{} | ||
for _, value := range values { | ||
steps = append(steps, resource.TestStep{ | ||
Config: testAccTFEWorkspace_basicWithAutoDestroyDuration(rInt, value), | ||
ExpectError: regexp.MustCompile("must be 1-4 digits followed by d or h"), | ||
}) | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckTFEWorkspaceDestroy, | ||
Steps: steps, | ||
}) | ||
} | ||
|
||
func TestAccTFEWorkspace_createWithSourceURL(t *testing.T) { | ||
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int() | ||
|
||
|
@@ -2978,14 +3054,30 @@ resource "tfe_organization" "foobar" { | |
} | ||
|
||
resource "tfe_workspace" "foobar" { | ||
name = "workspace-test" | ||
organization = tfe_organization.foobar.id | ||
auto_apply = true | ||
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_basicWithAutoDestroyDuration(rInt int, value string) 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_activity_duration = "%s" | ||
}`, rInt, value) | ||
} | ||
|
||
func testAccTFEWorkspace_operationsTrue(organization string) string { | ||
return fmt.Sprintf(` | ||
resource "tfe_workspace" "foobar" { | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately most of the raw config/state checking in this PR is due to this value being changed to
computed
. The main problem is insuring that unsettingauto_destroy_at
(whenauto_destroy_activity_duration
is also unset) sends a null value to the TFC API.