You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In many situation, I like to be able to accept a format string as input to allow for customization of things like AWS IAM role names or AWS Parameter Store keys. Because the format string allows indexed addressing of variables, this is a very flexible solution, because I can provide a static list of possible inputs and people can rearrange them as they like and omit variables they don't want.
# Construct the SSM parameter store key name for where to store the database user's passwordssm_key_name=format(var.format_string, var.region, var.stage, var.service, var.db_name, var.db_username)
So you can set
var.format_string = "/%[5]v"
and ssm_key_name will be set to "/${var.db_username}"
Attempted Solutions
This works if, and only if, the format string references the last variable in the list. Otherwise, it fails with an error too many arguments.
Proposal
Have some way to disable the check for too many arguments. Could be a separate function format_nocheck, could be a special flag in the format string, could be something else, but should not be a command line option. It should be something completely contained in the code.
Although the specific proposal is different, I think the underlying use-case you've shared here is the same as #26838, and so I'm going to close this one just to consolidate the design discussion over there. I expect we'd prefer to meet this use case using Terraform's own template language rather than the format minilanguage, because it's a superset of the format language (you can call format inside it) and it typically results in a template that is easier to understand without referring to the call in order to see which values are assigned into which positional arguments.
With that said, we'd ideally like to find a way to do it that doesn't lead to the need for writing escaped templates inside templates, because "$${foo}" instead of "${foo}" is pretty hard to write and maintain correctly. The desire for a more integrated solution is what has caused us to hold on solving this right now, until we have some time to do some more thorough design work.
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.
Current Terraform Version
Use-cases
In many situation, I like to be able to accept a
format
string as input to allow for customization of things like AWS IAM role names or AWS Parameter Store keys. Because theformat
string allows indexed addressing of variables, this is a very flexible solution, because I can provide a static list of possible inputs and people can rearrange them as they like and omit variables they don't want.So you can set
and
ssm_key_name
will be set to"/${var.db_username}"
Attempted Solutions
This works if, and only if, the
format
string references the last variable in the list. Otherwise, it fails with an errortoo many arguments
.Proposal
Have some way to disable the check for
too many arguments
. Could be a separate functionformat_nocheck
, could be a special flag in theformat
string, could be something else, but should not be a command line option. It should be something completely contained in the code.References
The text was updated successfully, but these errors were encountered: