Issues after upgrade to terraform 0.12

北战南征 提交于 2020-05-17 06:35:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!