templatefile function accept content and not just file path #33335
Labels
duplicate
issue closed because another issue already tracks this problem
enhancement
new
new issue not yet triaged
Terraform Version
Use Cases
TLDR: The "end goal" is to be able to use template files stored in locations external to the module/workspace consuming them.
The idea here is to be able to store and share templates outside of a terraform solution. one team would like to place template files in a repository that is accessible by multiple team members and the module in question would consume from that location.
Currently,
templatefile()
requires a file-path to a file co-located with the code. In contrast, the deprecatedtemplate_file
provider resource allows forcontent
which is more flexible as one can now use multiple data resources to get that template data from local files, to github repository files, to templates stored in a K/V system like paramstore."why not a heredoc string"?
Main reason here is heredoc, when interpreted, will accept any variable in the runtime, whereas use of
templatefile()
will let me set a map of vars that will be interpreted against, allowing one to protect vars I don't wish to expose.Attempted Solutions
Below snippet is a sterilized example where repositories are setup with circleci config.yaml files based on a template in a different repository. Some of the locals block is
The above works perfectly except for one detail: template provider is deprecated so there is preasure from my company to remove it in favor of templatefile() function. HOWEVER ... how? It doesnt seem possible to pass content to that function, hence the ask.
I attempted to replace
template_file
withlocal_file
but 1: this is not compatible with the function (it appears to ignore resource order when funning), 2: would mean a change would be detected every apply even if no change occurred (creating a temporary file),Proposal
Rather than assuming a path string is being passed in the first var, allow a keyword for content, such as:
Alternatively, add a new function called template(content, varsmap{}) that behaves otherwise identical to tempaltefile().
References
No response
The text was updated successfully, but these errors were encountered: