-
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
Delayed execution of reading for file variables #3354
Comments
A possible hack around this would be to use the Having a resource for reading files is probably the only way to make this delayed read work within the current config mechanism, since functions can't express dependencies. |
Yep @apparentlymart's suggestion is how I'd do it - use |
@lusis @apparentlymart @phinze Hey guys... I happened to find this topic very useful. I tried the suggestion myself but I might be doing something wrong. 😄 Having this code:
I would imagine from here I can just use
Am I doing something wrong? (using Terraform version |
@afiune Yeah having the same "no such file or directory in" problem. Looks like there is a check done on the paths in the variable interpolation in a phase before the actual run. If you create a empty "my_key" before the terraform apply, that key will be overwritten and used. Ugly hack but the only one that I have come up with to solve this. |
@HX-Rd It is exactly what I did. But it is very ugly indeed. Thanks for the answer though! 👍 |
@apparentlymart @afiune @HX-Rd @phinze Does anyone know if this "hack" is still functional in the newest Terraform? I'm having quite the time trying to do something like this. I am trying to have an md5 generated for a directory each time terraform runs, save the hash to a file, and use that file's contents to determine if provisioning needs to happen. If this is a far off use case feel free to let me know. My problem seems to be the policy-hash-file gets refreshed first. If I run twice in a row, the second time will pick up the necessary changes. Verified this by inspecting the state file directly.
This is all an elaborate scheme to run Chef when contents of a specific folder changes. Thanks. |
In order for the hack to work it is necessary to use the older (now deprecated) form of In the future I'd like to be able to address this sort of problem using the mechanism added by #8768. |
So I got this working in Terraform 0.9.10 with some slight tweaks on the above technique. Namely by using a combination of a computed resource for the filename and by depending on an intermediary resource for data. It looks like this:
of course this will surely break in 0.10.x :) |
Fellow travelers who land here, an update. As expected the hacky thing above (left for posterity) did in fact break with 0.10.x, but the External Data Source provider is awesome (once you get the hang of it). I've built an updated example here: https://gist.github.com/irvingpop/968464132ded25a206ced835d50afa6b |
Just wanted to drop in and mention that I've accomplished this using the TLS provider. Relevant docs: |
@ZoidBB That provider stores the key in statefile |
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. |
In an attempt to build some really reusable modules, we've broken a few things out. One thing we need is the ability to generate an AWS keypair for each environment we stand up. I discovered the null resource and thought it would help by wrapping the
ssh-keygen
process up into a resource that could then be used foraws_key_pair
. Evidently this doesn't appear to work as${file("foo")}
contents are required to be read before work can begin:terraform plan
andterraform apply
both fail as the file does not yet exist (apparently though I've not dug into the code yet) for reading. This is a normally safe sanity check so I totally understand WHY.Is there an option for lazy evaluation or is there a workaround that involves a dance around generating the keypair files locally and then some how cat'ing them out into a variable?
The text was updated successfully, but these errors were encountered: