-
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 attribute to resource and data source #1354
Conversation
bee7df9
to
17f66fa
Compare
c87fc41
to
615ea2e
Compare
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.
Is it worth documenting that once the destroy plan is run the auto_destroy_at
attribute will be deleted there will be a plan diff (drift)?
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.
tested locally and working as expected
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.
Just a few thought-provoking questions. I'm still trying to wrap my head around the IaC use case for this
@@ -68,6 +68,10 @@ The following arguments are supported: | |||
* `assessments_enabled` - (Optional) Whether to regularly run health assessments such as drift detection on the workspace. Defaults to `false`. | |||
* `auto_apply` - (Optional) Whether to automatically apply changes when a Terraform plan is successful. Defaults to `false`. | |||
* `auto_apply_run_trigger` - (Optional) Whether to automatically apply changes for runs that were created by run triggers from another workspace. Defaults to `false`. | |||
* `auto_destroy_at` - (Optional) A future date/time string at which point all resources in a workspace will be scheduled for deletion. Must be a string in RFC3339 format (e.g. "2100-01-01T00:00:00Z"). | |||
|
|||
~> **NOTE:** `auto_destroy_at` is not intended for workspaces containing production resources. Additionally, the field is partially managed by HCP Terraform so usage with any long-lived workspaces may cause a perpetual diff. |
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.
If the platform is going to change this value, I think it should be marked as computed in the schema to avoid 'perpetual diff' though I think it may still happen if the config is different. When does HCP Terraform change this value? After the auto destroy comes to pass?
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.
Marking it as computed would at least allow users to manage the workspace with the tfe provider but the auto-destroy-at configuration could be managed in the UI without causing drift in the next plan.
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.
"perpetual diff" is sloppy phrasing on my part, because the HCP Terraform API will respect the value set by the provider. but there will be contention because both pieces are effectively managing the workspace. I agree with your other comment that this doesn't make as much sense in an IaC context, however we have discussed this with enterprise teams and they have expressed a desire to control this specifically through the provider.
yeah, HCP Terraform will unset auto_destroy_at
after a destroy run occurs.
I did initially have this as a computed attribute but allowing the user to set "meaningful null" values added significantly more complexity (specifically where the user has set the value but then removes auto_destroy_at
from the TF config). what's in this PR ended up feeling like the provider SDK's preferred path for allowing for meaningful null values.
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.
we will need to make this computed, but the drift we'd be trying to work around is actually intended behavior that will be more explicit once we factor in logic around the duration attribute (update forthcoming here hashicorp/go-tfe#902). changes for the duration attribute will be compatible with the behavior in this PR.
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.
Is it the intention that a tfe_workspace without a auto_destroy_at config should unset any drifted autodestroy setting?
Usually this kind of drift correction is good but in the case of auto_destroy, it seems like terraform wouldn't be the best source of that config.
Methodology:
- create workspace using basic config with no auto destroy
- set up auto destroy in the UI
- terraform apply
Outcome:
terraform plans to unset the auto destroy setting
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.
Is it the intention that a tfe_workspace without a auto_destroy_at config should unset any drifted autodestroy setting?
By default, yes. Talked this through with @jondavidjohn and the way we're leaning (Jon correct me if I'm wrong) is how it's currently implemented because it allows the most flexibility for users.
@brandonc your argument makes sense: there are cases where the user may want to ignore changes to this specific field. If that's the case we can recommend that they use an ignore_changes
here. My argument is that as a user, there are cases where I would explicitly want to be alerted if somebody set auto destroy on my workspace – in this case I always want to show the diff.
If we specifically ignore the diff within the provider there's no way to override that behavior as a user, but there is more flexibility if we default to showing a diff.
@@ -68,6 +68,10 @@ The following arguments are supported: | |||
* `assessments_enabled` - (Optional) Whether to regularly run health assessments such as drift detection on the workspace. Defaults to `false`. | |||
* `auto_apply` - (Optional) Whether to automatically apply changes when a Terraform plan is successful. Defaults to `false`. | |||
* `auto_apply_run_trigger` - (Optional) Whether to automatically apply changes for runs that were created by run triggers from another workspace. Defaults to `false`. | |||
* `auto_destroy_at` - (Optional) A future date/time string at which point all resources in a workspace will be scheduled for deletion. Must be a string in RFC3339 format (e.g. "2100-01-01T00:00:00Z"). |
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.
I'm trying to imagine how a static date could be useful in the context of config. Likely this data would come from a variable, but aside from that it will be inevitable that they will define a relative time that will end up changing with every plan.
timeadd(timestamp(), "1h")
Description
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:{ "data": { "attributes": { "name": "some-workspace", "auto-destroy-at": "2006-01-02T15:04:05Z" }}}
{ "data": { "attributes": { "name": "some-workspace" }}}
{ "data": { "attributes": { "name": "some-workspace", "auto-destroy-at": null }}}
Remember to:
Testing plan
(these follow the integration tests added as part of these changes)
auto_destroy_at
unsetauto_destroy_at
auto_destroy_at
is set in state and that no further diff occurs with future plansauto_destroy_at
then removing in the updateExternal 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.
Tested against local TFE, but these
auto_destroy_at
changes are out in production TFC.