【发布时间】:2020-08-07 18:27:29
【问题描述】:
我想创建几个 EC2 实例并将它们的 private_ips 抓取到一个 ec2.ini 样式文件中,以便进一步与 Ansible 一起使用。
resource "local_file" "ec2_id" {
count = var.instance_count
content = "${aws_instance.instance[count.index].private_ip} ansible_ssh_user=ec2-user\n"
filename = "ec2.ini"
}
这总是打印最新创建的 EC2 实例的 private_ip。
知道如何解决这个问题。
更新:-
data "template_file" "hehe" {
count = var.instance_count
template = "${element(aws_instance.instance.*.private_ip, count.index)} ansible_ssh_user=ec2-user subnetmask=${element(split("/", data.aws_subnet.selected-subnet-id.cidr_block),1)}\n"
}
resource "local_file" "ec2_id" {
count = var.instance_count
content = "${element(data.template_file.hehe.*.rendered, count.index)}"
filename = "ec2.ini"
}
不起作用。给我最后创建的实例 private_ip。
【问题讨论】:
-
这能回答你的问题吗? using count.index in terraform?
标签: amazon-ec2 terraform terraform-provider-aws