-
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
non-obvious ordering of functions and resources #25162
Comments
One thing I notice regarding this is that the documentation does talk about it specifically, but perhaps not using terms that are clear enough to the target audience, and also the text is pretty buried at the end of a wall of other text:
Perhaps a way to start here would be to try to improve the docs situation around this to draw more attention to this behavior. Most functions don't interact with the surrounding environment and so the time they are evaluated isn't significant. For easy reference, the set of functions whose result depends on environmental stuff that can be modified by
|
Is there any plan to make some functions operate in the dependency graph, or to otherwise add functionality to render a template that can use calculated (applied) values, while also not being stuck to the primitives limitation of template_file? |
Hi @tculp, The |
@apparentlymart Thanks for the help. I had tried using that before but I kept getting "... values will be known after apply", but now it's working... I'm not sure what changed, but I'll keep a lookout to see if I get that behavior again Edit: I think I figured it out. I believe I had messed up the templating, but the "will be known after apply" message is printed informationally, but I mistook that to be the cause of the error |
I have a local-exec that creates a file, and then I use the sha of that file ( |
Returning to this some time later, I think it might be helpful to be a bit more specific about what exactly it might mean for functions to "respect the dependency graph": I know from related discussion about providers being configured during the planning phase that a lot of participants have a different idea about what exactly Terraform's "dependency graph" is used for and what it guarantees. Terraform uses its dependency graph primarily to ensure that expressions are evaluated in the correct order relative to one another. During the apply phase in particular it also affects the order of the planned side-effects, but that addition is specific to the apply phase and so isn't helpful for anything that happens before the apply phase. In particular, the dependency graph very little involvement in deciding what can happen in the planning phase vs. what must wait until the apply phase, or even to a future plan/apply round, because each phase has its own dependency graph used for its own evaluation process. Terraform has some other mechanisms, separate from the dependency graph, that it uses to model the fact that some decisions need to be made before Terraform has performed the actions that would decide the inputs:
Taking this feature request at face value then, it is asking for Terraform to have a rule for deciding that some functions should have their execution deferred until the apply phase under certain circumstances, and thus anything that would depend on the result of that function must also be somehow deferred until the apply phase. We already have a few functions that have simple deferral behavior. For example, the A naive interpretation of this request would have us make the filesystem access functions also always return unknown values during the planning phase, so the the file contents read are always those present during the apply phase. But that would make these functions considerably less useful for their currently-intended purpose, and even if not it would be a breaking change and so not possible under the Terraform v1.x Compatibility Promises. A more subtle compromise would be to change the functions to return unknown values only if they would otherwise have failed with an error, on the assumption that the error will probably go away during the apply phase. However:
So that idea doesn't seem quite right either. I'm not going to enumerate any more possibilities here, since this comment is already long, but suffice it to say that every alternative I've considered so far has encountered some significant drawback that either makes it not solve the assumed problem or comes at a significant cost to those already using these functions in the way they were intended to be used -- for reading files that are distributed along with the configuration and not modified at all during the apply step. Therefore this issue remains open in large part because it isn't clear that there is any satisfactory solution to it, even though we acknowledge that these functions are an attractive nuisance for someone new to Terraform who might misunderstand them as the way to read files in all cases. In practice, the With all of this said then, it seems to me that finding a way to clarify the situation better in our documentation remains the most plausible possibility for this issue. Documentation is not in my area of responsibility and so I cannot say exactly what ought to change, but it does seem that the current docs are not getting the point across sufficiently. (There is also room for changing the error messages that Terraform returns when these functions fail, but we are typically more constrained in that context due to error messages needing to be relatively concise and highly relevant or else people tend to just not read them at all.) |
Thank you for the extremely detailed response. I think this explains very well the difficulty/drawbacks of making this change. For what it's worth, I solved my specific problem using the Also, just as an aside, I thought the error message returned by terraform in this instance was clear and concise -- terraform can't be expected to know the file was missing because I expected some bash script to generate it beforehand. |
Current Terraform Version
Use-cases
I'm creating this as a tracking issue for a broad category of issues where people people do not realize that functions run early, and don't participate in the resource dependency graph, and encounter non-obvious behavior as a result.
Specific examples are things like trying to create a template file and then reference it using
templatefile
.Attempted Solutions
No specific workarounds listed yet - this is just to gather evidence to support some other refactor.
Proposal
No proposal yet - this is just a tracking issue to link issues of this nature as they come in.
References
The text was updated successfully, but these errors were encountered: