<<EOT
%{ for ip in aws_instance.example.*.private_ip ~}
%{ part0 = split(".", ${ip})[0] }
server ${part0}
%{ endfor ~}
EOT
Is there a way to get a variable assigned in the for block which can be used for later before the block completes
adding
%{ part0 = split(".", ${ip})[0] }
within for block shows "invalid template control keyword"
You are trying to define a variable (
part0) inside the template. I don't think you can define variables like that in a heredoc template. You're also trying to add an extra string interpolation (${}) inside thesplit()call, where string interpolation should not be used.Please try this: