-
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 ignores dependencies/order of operations for resources that are modified in place #31769
Comments
The example given is not missing any dependencies, the order of operations is well-defined and is being executing as they are defined. If it helps, think about the situation where Since this does not represent a bug in Terraform, I'm going to close the issue. If you have more questions, feel free to continue the conversation in the original forum thread. Thanks! |
@jbardin Yes, you are right, sorry, I tested it with If we would do that this way there would be no need to use For my particular case that seems to work, but I think having the ability to support two instances of resources at once is provider specific, right? So I still tend to think that it's the problem with core terraform functionality if you can't set the order of operations without creating two instances of resources at once. |
The overall order of resource actions must be consistent, regardless of whether the resource is being replaced, only deleted, or only updated. This is especially important in large configurations where it would be very confusing for users if removing vs replacing a resource subtly changed the overall order of operations causing other failures. Terraform must pick some order to use by default, and none of the choices can work for every possible configuration, so we always start from delete-then-create. Also, once you build out more complex graphs of dependencies, there are very few topological orders which can create a valid dependency graph at all. It's tempting to assume that the simple case where you want to swap the order of operations is valid, but once that is combined into arbitrarily large graphs of changes, cycles appear making the proposed order invalid. I made some notes to help explain the basics here if you're interested: https://github.com/hashicorp/terraform/blob/main/docs/destroying.md. |
Thank you for spending your time explaining that to me, I can't honestly say that I understood this document completely, so feel free to ignore my ramblings if I missed something entirely :) But again, as I said the problem with your scenario
Is not actually the order itself, but because we treat I can't see how the order of operations would break at all in any scenario if we just update the dependent resource twice. |
You cannot update the Besides the fact that the architecture of Terraform is not designed around being able to handle multiple updates like this, we also have to contend with the fact that providers (and hence the implementations of each resource) would never expect to have multiple updates to a single resource plan or apply operation. Say for instance the dependency was used in a required attribute on the |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Terraform Version
Terraform Configuration Files
https://github.com/vladimir-avinkin/terraform-dependency-order-repro
Debug Output
https://gist.github.com/vladimir-avinkin/f948eb7d4917e2c590d4d3172f70e144
Expected Behavior
Terraform should respect the order of operations for dependent resources, in this case, null_resource.null[1] should have been destroyed AFTER modifying hashicups_order.cup, not before
Actual Behavior
Despite the explicit and explicit dependency terraform destroyed null_resource.null[1] before modifying hashicups_order.cup
Steps to Reproduce
Clone the repository, ensure that you have the required tools that are listed in README.md, then run:
In that last apply you will see that terraform deletes
null_resource.null[1]
before modifyinghashicups_order.cups
despitehashicups_order.cups
implicit and explicit dependenciesAdditional Context
No response
References
The text was updated successfully, but these errors were encountered: