-
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
No way to use data "template_file" on a file generated on the fly by local-exec as it fails during planning #8406
Comments
data "template_file"
on a file generated on the fly local-exec
as it fails during plan
This is kind of working as intended but there are definite buggy behavior in here. Data sources cannot depend on resources (we should've given you an error, we didn't, that's a bug) since data sources must be able to run prior to any resources. This is the point of data source: to give you data that is external to Terraform that isn't dependent on the ordering of Terraform's execution. At least, that's how they work in their current form. I think the primary issue here is that we didn't give you a config validation error. There are other issues like #8144 (referenced) that aim to solve your use case. |
@mitchellh what you described there isn't entirely correct: a data source can depend on a resource, but that causes its resolution to be deferred until the apply phase. In this case they appear in the plan output as "read" actions, with the I think the issue here is more that interpolation functions are dealt with during the validation pass as well as other passes, but during validation the file will of course not exist yet. Using the I think a more robust solution to this class of problem (I need to get some data or do some operation that Terraform doesn't support but that I can script) is something like what I proposed in #8144. Under that proposal, it becomes possible to execute external programs as data sources, rather than only as provisioners, and thus they can interact more reasonably with other data sources and resources. |
@mitchellh thanks - I also noticed that file names in quotes are treated like files that must exist, whereas variable names that represent filenames go unquoted and are not validated when running |
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 v0.7.1
Affected Resource(s)
Terraform Configuration Files
Debug Output
Expected Behavior
I (perhaps incorrectly) assumed that
terraform plan
wouldn't require that a file referenced byfile()
needed to exist during the plan stage, but would fail on it being missing duringterraform apply
.I suppose this could be considered intended behavior, and that a better solution would be to have something like
tmp_file()
as afile()
alternative, or a core way to capture alocal-exec
output into a variable instead of a temp file?Actual Behavior
terraform plan
fails on not finding a file that had yet to be generated by a dependentnull_resource
.Steps to Reproduce
terraform plan
The text was updated successfully, but these errors were encountered: