次のように私はAWSあちこちテラフォームのスクリプトを書くことに助けが必要:異なる地域でセキュリティグループのルールを適用する方法はありますか?
私は例えば、 、複数の地域でのセキュリティグループのリストを持っている - 私たち-東-2 - 米国西部-1 - など
ここで、いずれかの地域で新しいインスタンスを追加すると、EIPが適用されます。 すべての地域のセキュリティグループにすべてのトラフィックを追加する必要があります。
これまでのところ、私が試した何:
- セーブEIP
- node_ips.txtと呼ばれるファイルで、そのファイルを読む
- ここではセキュリティグループに
それを適用するスクリプトですサンプル:
variable "list_eips" { type=list" }
resource "aws_eip_association" "eip_assoc" {
count = "${local.number_of_instances}"
instance_id = "${element(aws_instance.ec2_instance.*.id, count.index)}"
allocation_id = "${element(data.aws_eip.db_ip.*.id, count.index)}"
provisioner "local-exec" {
command = "echo ${self.public_ip} >> node_ips.txt"
}
}
data "template_file" "read_node_ips" {
template = "${file("${path.cwd}/node_ips.txt")}"
}
resource "aws_security_group_rule" "allow_db_communication" {
type = "ingress"
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["${split(",", "${join("/32,", concat(compact(split("\n",data.template_file.read_node_ips.rendered)),var.list_eips) )}/32")}"]
security_group_id = "${data.aws_security_group.cassandra_sg.id}"
}
Th私のために働いていません。 list_eipsのルールだけを追加しています。 また、別の地域に新しいインスタンスを追加すると、秘密グループが異なります。だから、私は前の地域の私のセキュリティグループは何か知ることができません。 アドバイスをお願いします。
ありがとうございました。