问题
It's sad that terraform is not backward compatible.
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}"
}
but after upgrading it to Terraform 0.12 I have started facing issues and I am not able to get the syntax for TF0.12.
Error: Missing resource instance key
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}"
Because aws_instance.ec2_instance has "count" set, its attributes must be accessed on specific instances.
I tried "${aws_instance.ec2_instance[count.index].primary_network_interface_id}" but no luck.
来源:https://stackoverflow.com/questions/61727500/issues-after-upgrade-to-terraform-0-12