-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
templatestring function allow for_each #35274
Comments
Hi @reasland! Thanks for this feedback. Here's a different way you could write this which I would expect to work with the function as currently implemented: resource "aws_cloudfront_function" "functions" {
for_each = data.http.function_data
name = each.key
runtime = var.functions[each.key].runtime
comment = try(var.functions[each.key].comment, "")
code = templatestring(each.value.response_body, var.functions[each.key].values)
} The general idea I followed here was to pivot to declaring one function per However, I'm also going to investigate what it would take to also carve out support for what you tried here, since what you tried is indeed a reasonable thing to write to allow selecting a template dynamically for each element of a collection. |
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. |
Terraform Version
Use Cases
I am importing template files via the data HTTP resource, I give a list of files to import in a variable then use a for_each to import multiple items specified in configuration
Attempted Solutions
above errors with this
Invalid value for "template" parameter: invalid template expression: must be a direct reference to a single string from elsewhere, containing valid Terraform template syntax.
when I hardcode the each.key the issue is resolved, so I believe the current implementation of templatestring does not allow variables in the template section
I am able to use the hashicorp/template_file resource to bypass this issue, but that provider is depricated
Proposal
Allow variables to be used in templatestring() function in the template segment
References
No response
The text was updated successfully, but these errors were encountered: