-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Terraform apply destroys resources that are still referenced from other resources #31309
Comments
Hi @prashantv, Thanks for filing the issue, and the extensive references you've collected! As you've mentioned, the only solution presented by Terraform to obtain this order of operations is
Unfortunately this means as of now the problem falls mostly on the providers. Any resource which requires this sort of "registration pattern" should be designed to allow Even in the case that a usable provider-forced option for a new ordering were possible, it would still be up to the providers to implement. Seeing the number of cases where While we're not opposed to the possibility of such a feature, there haven't yet been any proposals which could meat the two fundamental requirements of; not imposing changes on resources outside of that provider's control, not causing cycles in arbitrarily large or complex graphs. Since Terraform is working as designed here, I'm going to re-label this as an enhancement proposal. This can more or less serve as the core equivalent of hashicorp/terraform-plugin-sdk#585, which is meant to cover the same usability aspects. Thanks! |
Terraform Version
Terraform Configuration Files
This configuration relies on a dummy provider, see github/prashantv/terraform-dep-order-repro
ref
After applying the above, remove "n2" and the reference to it,
Applying this will fail as n2 is destroyed first, while there is still a policy referencing it.
Debug Output
https://gist.github.com/prashantv/45859f8607e690ff22990c310381f8c8
Expected Behavior
When the config removing "n2" is applied, the reference is removed first, and then n2 is removed successfully.
Actual Behavior
Terraform tries to remove "n2" before updating the policy reference, and the remove fails since the notifier is still referenced by a policy.
Steps to Reproduce
Full steps for reproduction are in the repo.
Summary is:
Additional Context
There is a workaround which causes the destroy to happen after the update: setting the lifecycle meta-argument
create_before_destroy
. This has to be set on the resoruce and applied before the delete operation. However, this workaround has some issues:create_before_destroy
.create_before_destroy
is not appropriate for some resources. If a resource has a field that must be unique (e.g.,name
), and a separate attribute that hasForceNew
, thencreate_before_destroy
is not compatible with these resources, so the workaround does not work. We acutally have this combination -- the notifier resource has a name that must be unique, and a user-selected immutable ID field that usesForceNew
, socreate_before_destroy
shifts the problem to users being unable to change names.Ideally the solution would be:
ForceNew
fields).References
There are a few existing issues which are almost all closed:
create_before_destroy
is recommended in many of the above, but as mentioned in "Additional Context", it's a workaround with drawbacks rather than a solution to this problem.The text was updated successfully, but these errors were encountered: