-
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
template_file: whether or not changes show up in plans feels inconsistent #8021
Comments
Hi @glasser. Thanks for this report! Is this problem unique to this particular configuration, or have you seen it happen with other data sources too? I ask because I'm wondering if having that It looks like the problem goes away if the interpolation in the template is escaped: data "template_file" "foo" {
template = "$${bar}"
vars {
bar = "baz"
}
} With the configuration written this way, the Does that solve the problem for you, or are you seeing similar issues with other data sources? Thanks! |
I can look more into this on Monday, but does anyone use template_file
without computed attributes? I'm assuming without checking that ${file()}
also counts as computed...
Certainly, the identical template_file as a resource did not show up in the
diff on every plan.
|
Also I'm moderately sure that even in my case, the interpolation is handled
by template_file, since bar is not defined in any other context. Hmm.
|
@glasser I suspect that the unescaped template is just working "by accident", due to Terraform failing to validate/error that the variable is undefined. It seems like what's happening here is that Terraform is detecting I think the intended behavior here is that your original template would be an error ( If this is indeed the problem, and escaping the template interpolations is the solution, I think there's definitely some documentation work here (to mention in the |
@apparentlymart OK, I edited the title since it clearly seems to be hyperbolic. I agree that ensuring that the substitutions show up only after the initial round of substitutions seems to work better. And my theory that On the other hand, I'm now seeing problems that go in the opposite direction:
So it seems like running |
I think you're asking why running The reason you don't see any plan output for changes to a data block is that it was handled during the "refresh" phase, as you can see by this log line in all three of the commands you ran:
The most significant difference between a data resource (a resource created with a The exception to this rule is when the data resource's arguments interpolate values from managed resources that don't yet exist. In that case, we can't refresh the data until the resource has been created, which we signal in the plan with the "read" (
In the above situation, the read action would appear only on the first run, since on subsequent runs we'd have a value for These read actions are included in the plan in order to make the plan "complete": if you see a resource attribute in the plan that interpolates Terraform will only include the data resource in the plan if it depends on a resource that hasn't been created yet. Otherwise, it'll refresh it before the plan phase even begins, and shouldn't be mentioned in the plan at all. I hope that clarifies the situation a little. In an early iteration of this feature we didn't ever include data reads in the plan, but we felt it was better to include it so that the user would be able to see the complete picture of what would happen once the plan is applied. |
OK, that mostly makes sense to me. And when the top level interpolator saw We've been using "inline templates" like this for a while but I guess we'll switch to either escaping the |
I opened #8077 to capture the bug that this wasn't raised as an error. If we choose to update the docs about this gotcha then we could do it as part of that issue, so I'm going to close this one. 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. |
Terraform Version
v0.7.0
Affected Resource(s)
Core (data sources)
Terraform Configuration Files
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
terraform apply
terraform plan
Expected Behavior
plan
would only tell me about things that changed.Actual Behavior
plan
says this every time:Reasoning
Yes, I get that data sources have a special format. But my project has a dozen or two resources that could be converted to data sources (template_files and a custom resource). And many of them have pretty verbose attributes. Having the complete contents of all of them print on every single
terraform plan
for the rest of time will make it hard to find the actual changes.The text was updated successfully, but these errors were encountered: