Hi @iamdempa,
That seems like a good use-case for the templatefile
function, which use Terraform’s string template syntax with templates in external files.
For example, you could create a new file roles.ini.tmpl
(or whatever you want) in the same directory as your module’s .tf
files with the following content:
[kube-master]
%{ for addr in master_ip_addrs ~}
${addr}
%{ endfor ~}
[kube-minion]
%{ for addr in minion_ip_addrs ~}
${addr}
%{ endfor ~}
Then replace your content
expression with a call to render that template:
content = templatefile("${path.module}/roles.ini.tmpl", {
master_ip_addrs = aws_instance.kubernetes_master[*].public_ip
minion_ip_addrs = aws_instance.kubernetes_minion[*].public_ip
})