Error: Template fails to render
Affected lines:
OTHER_IPS=( ${ALL_IPS[@]/{$IP}/} )
echo "Instance IP is: $IP, Cluster IPs are: ${ALL_IPS[@]}, Other IPs are: ${OTHER_IPS[@]}"
Terraform Version:
0.8.3
Link to userdata template:
https://github.com/arehmandev/Consul-bashstrap/blob/master/consul-node.sh
Workaround:
Could not seem to escape the @ character with my efforts, so I ended up executing it as such:
Hi @arehmandev. Sorry for the weirdness here.
The issue here appears to be the ${ sequences rather than the at signs... That is causing Terraform to treat these sequences as interpolation expressions, which then fails because the at sign is not valid interpolation syntax.
You can avoid this by replacing the ${ sequences with $${. Terraform treats this as an escape sequence and then removes the extra dollar sign to get the literal sequences I think you wanted here.
Update: ALL WORKING! :) Thanks alot @apparentlymart, should've guessed it was the damn double dollar again.
I hit this error myself when trying to iterate on an array in bash embedded in a template_file for rendering. Escaping did not help as changing from for i in "${IP_ADDRS[@]}" to for i in "$${IP_ADDRS[@]}" still gives me the error: failed to render : parse error at 15:22: expected expression but found invalid sequence "@"
@apparentlymart @arehmandev was there anything else you did to work around this?
@metral it's tough to guess what's going on there. Also tricky to track ongoing Q&A on github, so I suggest instead looking to one of the forums listed on the Community page; in this case one if the Stack Exchange sites would probably be best so it's easy to share a more representative snippet of your configuration.
Hello All,
I'd like to report that this is still an issue. Error return and script component below.
Error: Error refreshing state: 1 error(s) occurred:
* data.template_file.template: 1 error(s) occurred:
* data.template_file.template: data.template_file.template: failed to render: parse error at 101:33: expected expression but found invalid sequence "@"
Here is the code from the bash script
for element in "${sitearray[@]}"
do
echo $element
done
Running terraform:
Terraform v0.11.10
+ provider.aws v1.50.0
+ provider.random v2.0.0
+ provider.template v1.0.0
Just to enforce the idea that this is still a bug/issue pending with latest versions of Terraform + provider.template:
Terraform v0.12.18
+ provider.template v2.1.2
This post relates to https://github.com/hashicorp/terraform/issues/19566#issuecomment-572552417
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 @arehmandev. Sorry for the weirdness here.
The issue here appears to be the
${sequences rather than the at signs... That is causing Terraform to treat these sequences as interpolation expressions, which then fails because the at sign is not valid interpolation syntax.You can avoid this by replacing the
${sequences with$${. Terraform treats this as an escape sequence and then removes the extra dollar sign to get the literal sequences I think you wanted here.