【问题标题】:Error: "network_interface": conflicts with vpc_security_group_ids错误:“network_interface”:与 vpc_security_group_ids 冲突
【发布时间】:2021-01-03 01:44:59
【问题描述】:

我正在尝试使用 aws_network_interface 创建一个 aws 实例,如下所示:

resource "aws_network_interface" "lustre-mds01" {
  subnet_id   = "${var.subnet_id}"
  private_ips = ["10.1.0.10"] 
}

resource "aws_instance" "lustre-mds01" {
  ami                    = "${var.ec2_ami}"
  instance_type          = "t2.nano"
  key_name               = "${var.key_name}"
  vpc_security_group_ids = [ "${var.vpc_security_group_id}" ]

  root_block_device {
    volume_type = "gp2"
    volume_size = 128
  }

  network_interface {
    network_interface_id = "${aws_network_interface.lustre-mds01.id}"
    device_index         = 0
  }
}

但是,这会导致:

错误:“network_interface”:与 vpc_security_group_ids 冲突

这似乎存在问题,但由于不活动,票证已关闭。我是一个 terraform 菜鸟,所以我不确定这看起来像是一个错误还是只是用户错误。

我的环境:

$ terraform -v
Terraform v0.12.2
+ provider.aws v2.15.0
+ provider.external v1.1.2
+ provider.local v1.2.2
+ provider.null v2.1.2

【问题讨论】:

    标签: amazon-web-services terraform terraform-provider-aws


    【解决方案1】:

    aws_network_interface resource 允许您为接口设置安全组(安全组由 ENI 限定,因此这是有道理的)因此,如果您定义 network_interface 块,那么您将覆盖默认 ENI,因此可以'不在实例级别指定安全组。

    所以在你的情况下,你可能想要这样的东西:

    resource "aws_network_interface" "lustre-mds01" {
      subnet_id       = "${var.subnet_id}"
      private_ips     = ["10.1.0.10"]
      security_groups = ["${var.vpc_security_group_id}"] 
    }
    
    resource "aws_instance" "lustre-mds01" {
      ami           = "${var.ec2_ami}"
      instance_type = "t2.nano"
      key_name      = "${var.key_name}"
    
      root_block_device {
        volume_type = "gp2"
        volume_size = 128
      }
    
      network_interface {
        network_interface_id = "${aws_network_interface.lustre-mds01.id}"
        device_index         = 0
      }
    }
    

    但是,我会质疑为什么你在这里替换默认的 ENI,而直接在 aws_instance resource 中设置实例的私有 IP 地址要简单得多:

    resource "aws_instance" "lustre-mds01" {
      ami                    = "${var.ec2_ami}"
      instance_type          = "t2.nano"
      key_name               = "${var.key_name}"
      subnet_id              = "${var.subnet_id}"
      private_ip             = "10.1.0.10"
      vpc_security_group_ids = ["${var.vpc_security_group_id}"]
    
      root_block_device {
        volume_type = "gp2"
        volume_size = 128
      }
    }
    

    使用数据源来选择security groupAMI,而不是为它们传递不透明的ID,您也可能会从中受益。这使他们能够更加自我记录。

    【讨论】:

      猜你喜欢
      • 2016-09-17
      • 2017-07-25
      • 2018-04-05
      • 2020-10-14
      • 2021-08-07
      • 2018-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多