我正在尝试使用AWS_NETWORK_INTERFEFE创建一个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地址时,我会在此处替换默认ENI:
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。这使他们能够更加自我记录。