-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Outputs are evaluated before resource updates which can cause unnecessary errors #23365
Comments
Hi @antonosmond! Sorry for this weird behavior, and thanks for reporting it. Although the details are a little different, this problem is in the same family of problems as discussed in #17034 for data resources: Terraform currently has a separate "refresh" step that runs before planning, and that step can get itself into a strange state where values in existing objects have changed but we've not yet considered the possibility of new objects being created or existing objects being destroyed. The fix for this one is likely to be in the same overall area as for #17034: we need to merge the refresh step into the plan step so that refreshing and planning happen at the same time, and thus Terraform will be able to react to changes it detects during planning when dealing with objects such as data resources and outputs that can often be evaluated immediately without waiting for the apply step. We're going to leave this issue open because it's describing a different problem, but we wanted to leave a connection between the two here as a reminder that the solutions for them both are probably overlapping quite a bit. |
@teamterraform Thanks for the reply. These kinds of issues have caused me a lot of frustration over the last few years. My experience has been that terraform is great at apply => destroy cycles, however given an apply => modify => apply cycle, it really struggles. |
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. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Terraform Version
Terraform Configuration Files
Expected Behavior
Given the above config, I run
terraform apply
.Everything should run successfully and my outputs should be as expected.
Then I decide I no longer need
bar
so I remove it frommy_list
and runterraform apply
.I'd expect this to work.
Actual Behavior
I get the following error:
Steps to Reproduce
terraform init
terraform apply
bar
frommy_list
terraform apply
Additional Context
I can understand why it's failing - zipmap requires that the 2 lists are of equal length and the removal of
bar
from the list means this is no longer true on the second apply however I'd expect the output to be evaluated AFTER the resource updates.I'd expect the following order of events:
var.my_list
(length has changed from 2 to 1)random_uuid.example
andcount = length(var.my_list)
(count has changed from 2 to 1)random_uuid.example[1]
due to the changed countoutput.example
wherevar.my_list
now has a length of 1 andrandom_uuid.example.*.id
also now has a length of 1.I assume there's some validation happening before the resource is updated and the new
var.my_list.length
is being compared against the oldrandom_uuid.example.length
The text was updated successfully, but these errors were encountered: