Terraform v0.9.6
Please list the resources as a list, for example:
I want to use a shell script as-is and later use its "rendered" value at multiple places. So I did
data "template_file" "setup" {
template = "${file("config/setup.sh")}"
}
My script "setup.sh" contains a line:
hostname -b ${host_name}
When I do plan, Terraform complains:
Error refreshing state: 1 error(s) occurred:
* data.template_file.setup: 1 error(s) occurred:
* data.template_file.setup: data.template_file.setup: failed to render : 10:29: unknown variable accessed: host_name
Can I tell Terraform not to perform interpolation for this data source?
OR
Is there any other data source that I can use?
Regards,
Shantanu
Hi @shantanugadgil!
Recently we added a local provider, which so far just had a resource for writing a local file, but when it was added we anticipated having a data source for reading at some later point... it just didn't get done yet, unfortunately.
In the mean time, a trick you can do with the existing data source is to load the file into a template _variable_ instead, and then set the template itself to just insert that variable and nothing else. A file loaded into an element of the vars map won't be processed as a template.
Yes, I had noticed the "local" provider with the file-writing capabilities.
Awesome trick with the variable!!! 😃
_Though would be very confusing to the next person reading the code!_
Is the simple data source planned any time soon?
I think my options are:
${myvar} to $myvar is shell scripts. (not recommended)Regards,
Shantanu
@shantanugadgil the local_file data source is not something the Terraform team at Hashicorp has on the short-term list right now, but I'd be happy to review a PR for it if someone had the time and motivation to do it.
Otherwise, it's currently on my "rainy day list", as a quick thing that should be easy to get done if I find myself with a spare moment, :grin: but other stuff is unfortunately a higher priority right now.
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.
Most helpful comment
Hi @shantanugadgil!
Recently we added a
localprovider, which so far just had a resource for writing a local file, but when it was added we anticipated having a data source for reading at some later point... it just didn't get done yet, unfortunately.In the mean time, a trick you can do with the existing data source is to load the file into a template _variable_ instead, and then set the template itself to just insert that variable and nothing else. A file loaded into an element of the
varsmap won't be processed as a template.