可悲的是,terraform不向后兼容。
data "aws_security_group" "security_groupdev" {
filter {
name = "group-name"
values = ["SecurityGroupdev"]
}
}
resource "aws_instance" "ec2_instance" {
count = "${var.ec2_instance_count}"
...
}
resource "aws_network_interface_sg_attachment" "sg_attachment" {
security_group_id = "${data.aws_security_group.security_groupdev.id}"
network_interface_id = "${aws_instance.ec2_instance.primary_network_interface_id}"
}
但是将其升级到Terraform 0.12之后,我开始遇到问题,并且无法获取TF0.12的语法。
错误:缺少资源实例密钥
on ..\resources\ec2_instance\main.tf line 101, in resource "aws_network_interface_sg_attachment" "sg_attachment":
101: network_interface_id = "${aws_instance.ec2_instance.primary_network_interface_id}"
由于aws_instance.ec2_instance设置了“ count”,因此其属性必须为 在特定实例上访问。
我尝试了“ $ {aws_instance.ec2_instance [count.index] .primary_network_interface_id}”,但是没有运气。