Dear Team,
I have faced this error while trying to create null_resource using output ip address from module.par1
The question is what is the correct format to get the host ip address from the module.par1?
Terraform plan and terraform validate works perfect without errors.
output "par1-name" {
value = module.par1.name
}
output "par-1-public_ip" {
value = module.par1.public_ip
}
output results:
terraform output
par-1-public_ip = [
"163.172.x.x",
"51.15.x.x",
"163.x.x.111",
]
par1-name = [
"YB-DB-1-par1",
"YB-DB-2-par1",
"YB-DB-3-par1",
]
Here is Null_resource with the problem.
resource "null_resource" "set_hosts_file" {
depends_on=[module.par1]
count = module.par1.node_count
provisioner "remote-exec" {
inline = [<<EOT
%{ for ip in module.par1.*.private_ip ~}
echo ${ip} >> /root/ips.txt
%{ endfor ~}
%{ for name in module.par1.*.name ~}
echo ${name} >> /root/names.txt
%{ endfor ~}
paste /root/ips.txt /root/names.txt > /root/hosts.final
EOT
]
connection {
type = "ssh"
user = "root"
private_key = file("~/.ssh/id_rsa")
host = element(module.par1.*.public_ip, count.index)
}
}
}
thank you in advance for your support.
Vasilios Tzanoudakis