-
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
Terraform does not apply planned changes when a plan file is used, #20567
Comments
Hi @stefano-cherchi ! It will help us to see the debug output of the misbehaving terraform apply command. You can run |
@mildwonkey I ran into the same problem with terraform 0.11.13: |
@sryabkov - great question! Go ahead and share what you have here, please. We'd love to get a reproducible test case. Thanks! |
@mildwonkey The detailed debugging info is available here: https://gist.github.com/sryabkov/1aa9548bbd909a76b43fd9b67150b075 |
Thanks @sryabkov, this is a fantastic write up and very helpful information. Would you mind sending along one more piece of information? It would be very helpful to see the full trace log from the
|
@mildwonkey thank you, will do shortly |
@mildwonkey I updated the gist with the trace for the apply operation from a pre-generated plan. Here is the direct link: https://gist.github.com/sryabkov/1aa9548bbd909a76b43fd9b67150b075#file-tf_apply_from_saved_plan_trace-log |
After reading through the trace log, I see the following curious entry:
I'm not sure why that wasn't being returned as a proper error or why it wasn't visible at Looking at your configuration, I notice that the resource "google_project_iam_member" "project" {
count = "${data.template_file.projects_permissions.count}"
project = "${element(split(",", data.template_file.projects_permissions.*.rendered[count.index]),0)}"
role = "${element(split(",", data.template_file.projects_permissions.*.rendered[count.index]),1)}"
member = "${element(split(",", data.template_file.projects_permissions.*.rendered[count.index]),2)}"
} I think the cause of the problem here, then, is that the data resource got processed early on during the refresh phase and so Terraform didn't include it in the plan at all -- as far as it was concerned, all of the work for it was done already. Because Terraform didn't visit the data resource during the apply phase, it didn't get the opportunity to run the interpolator on the In the forthcoming Terraform v0.12 (what is currently represented by the Unfortunately I expect a fix for this issue in Terraform v0.11 is not practical because it would require replicating similar refactoring we did for v0.12 into the very-differently-designed v0.11 interpolator. Therefore I think the best we can do about it for now is a workaround: instead of using the count of one resource to populate another, instead make the count expression a named local value and interpolate it into both places: locals {
project_permissions_count = "${length(var.big_query_project_names) * length(var.gcp_bigquery_project_iam_permissions)}"
}
data "template_file" "projects_permissions" {
count = "${local.project_permissions_count}"
# ...
}
resource "google_project_iam_member" "project" {
count = "${local.project_permissions_count}"
# ...
} What we may be able to do for v0.11 is to figure out why this error is only appearing as a warning in the logs, and not as a real error message. But the error message itself is not particularly helpful, so that would only go so far here. Since the Terraform team at HashiCorp is currently 100% focused on completing the v0.12.0 release, unfortunately I expect that upgrading to v0.12.0 once it's released will end up being the best remedy we can manage here. @stefano-cherchi, it looks like the same is true in your situation: you're also using the |
@apparentlymart Martin, thank you very much for the detailed explanation of what's going on. I tried your suggested workaround, and it worked, so thank you for unblocking us. I agree it doesn't make much sense to try to retrofit the fix for this issue into v0.11, but I also think that v0.11 should throw an error and return a non-zero completion code so that downstream (or upstream?) tools (in our case, |
Hello! 🤖 This issue relates to an older version of Terraform that is no longer in active development, and because the area of Terraform it relates to has changed significantly since the issue was opened we suspect that the issue is either fixed or that the circumstances around it have changed enough that we'd need an updated issue report in order to reproduce and address it. If you're still seeing this or a similar issue in the latest version of Terraform, please do feel free to open a new bug report! Please be sure to include all of the information requested in the template, even if it might seem redundant with the information already shared in this issue, because the internal details relating to this problem are likely to be different in the current version of Terraform. Thanks! |
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. |
After some EC2 instance has been stopped and started again, I run
terraform plan -out foo.plan
and Terraform outputs this as expected, since instance's IP and hostnames have changed:When I run
terraform apply "foo.plan"
this is the result:If I run
terraform apply
with no plan file, instead, changes are applied as expected:Terraform Version
Terraform Configuration Files
Expected Behavior
Planned changes should be applied when a plan file is passed to the
terraform apply
commandActual Behavior
Planned changes are applied only if no plan file is used. If a plan file is passed as argument to
terraform apply
, the command returns no error but planned changes are completely ignored.Steps to Reproduce
terraform plan -out foo.plan
terraform apply "foo.plan"
Additional Context
none
References
none
The text was updated successfully, but these errors were encountered: