Skip to content
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 8 commits into from
Jun 25, 2024

Conversation

notchairmk
Copy link
Member

@notchairmk notchairmk commented Jun 12, 2024

Description

Adds auto_destroy_activity_duration to the tfe_workspace resource.

Requires #1378

Remember to:

Testing plan

  1. create a workspace resource with auto_destroy_activity_duration
    • example from test:
    resource "tfe_workspace" "foobar" {
      name                           = "workspace-test"
      organization                   = tfe_organization.foobar.id
      auto_apply                     = true
      file_triggers_enabled           = false
      auto_destroy_activity_duration = "1d"
    }
    
  2. apply configuration
  3. confirm that there are no pending changes on subsequent applies

External links

Include any links here that might be helpful for people reviewing your PR. If there are none, feel free to delete this section.

Output from acceptance tests

Please run applicable acceptance tests locally and include the output here. See testing.md to learn how to run acceptance tests.

If you are an external contributor, your contribution(s) will first be reviewed before running them against the project's CI pipeline.

$ TFE_HOSTNAME=<hostname> TFE_TOKEN=<token> TESTARGS='-run "TestAccTFEWorkspace(DataSource)?_(create|update|read)(With)?AutoDestroy(At|Duration)"' make testacc
TF_ACC=1 TF_LOG_SDK_PROTO=OFF go test $(go list ./... |grep -v 'vendor') -v -run "TestAccTFEWorkspace(DataSource)?_(create|update|read)(With)?AutoDestroy(At|Duration)" -timeout 15m
?   	github.com/hashicorp/terraform-provider-tfe	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/terraform-provider-tfe/internal/client	0.205s [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/terraform-provider-tfe/internal/logging	0.269s [no tests to run]
?   	github.com/hashicorp/terraform-provider-tfe/internal/provider/validators	[no test files]
?   	github.com/hashicorp/terraform-provider-tfe/version	[no test files]
=== RUN   TestAccTFEWorkspaceDataSource_readAutoDestroyAt
--- PASS: TestAccTFEWorkspaceDataSource_readAutoDestroyAt (9.94s)
=== RUN   TestAccTFEWorkspaceDataSource_readAutoDestroyDuration
--- PASS: TestAccTFEWorkspaceDataSource_readAutoDestroyDuration (9.72s)
=== RUN   TestAccTFEWorkspace_createWithAutoDestroyAt
--- PASS: TestAccTFEWorkspace_createWithAutoDestroyAt (6.47s)
=== RUN   TestAccTFEWorkspace_updateWithAutoDestroyAt
--- PASS: TestAccTFEWorkspace_updateWithAutoDestroyAt (10.93s)
=== RUN   TestAccTFEWorkspace_createWithAutoDestroyDuration
--- PASS: TestAccTFEWorkspace_createWithAutoDestroyDuration (5.22s)
=== RUN   TestAccTFEWorkspace_updateWithAutoDestroyDuration
--- PASS: TestAccTFEWorkspace_updateWithAutoDestroyDuration (13.36s)
PASS
ok  	github.com/hashicorp/terraform-provider-tfe/internal/provider	56.030s

@notchairmk notchairmk requested a review from a team June 12, 2024 18:06
@@ -112,9 +116,29 @@ func resourceTFEWorkspace() *schema.Resource {

"auto_destroy_at": {
Type: schema.TypeString,
Computed: true,
Copy link
Member Author

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 unsetting auto_destroy_at (when auto_destroy_activity_duration is also unset) sends a null value to the TFC API.

go.mod Outdated Show resolved Hide resolved
@notchairmk notchairmk force-pushed the notchairmk/workspace-auto-destroy-duration branch from bf992b3 to c1c4cd0 Compare June 14, 2024 02:44
@notchairmk notchairmk force-pushed the notchairmk/workspace-auto-destroy-duration branch from c1c4cd0 to 6074f95 Compare June 14, 2024 02:49
@notchairmk notchairmk marked this pull request as ready for review June 14, 2024 02:49
@notchairmk notchairmk requested a review from a team as a code owner June 14, 2024 02:49
Copy link
Member

@jfreda jfreda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looking good so far! I'm going to take it for a test run and will report back.

internal/provider/resource_tfe_workspace.go Outdated Show resolved Hide resolved
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"auto_destroy_at"},
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^\d{1,5}[dh]$`), "must be 1-5 digits followed by d or h"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be

Suggested change
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^\d{1,5}[dh]$`), "must be 1-5 digits followed by d or h"),
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^\d{1,4}[dh]$`), "must be 1-4 digits followed by d or h"),

Copy link

@emailnitram emailnitram Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edge case but 0d or 0h seems to be a valid value but fails when trying to apply

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edge case but 0d or 0h seems to be a valid value but fails when trying to apply

validation is mostly an additional nice-to-have to give the user early feedback. I'm fine with the logic here not needing to 100% match the business logic in the API, since it's an edge case

@emailnitram
Copy link

functionality looks good. tested and working as intended

@notchairmk notchairmk merged commit 863e9f2 into main Jun 25, 2024
9 checks passed
@notchairmk notchairmk deleted the notchairmk/workspace-auto-destroy-duration branch June 25, 2024 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants