繁体   English   中英

错误:“network_interface”:与 vpc_security_group_ids 冲突

[英]Error: "network_interface": conflicts with vpc_security_group_ids

我正在尝试使用 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 noob,所以我不确定这看起来像一个错误还是只是用户错误。

我的环境:

$ 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

aws_network_interface资源允许您为接口设置安全组(安全组由 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资源中设置实例的私有 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
  }
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM