Chr*_*now 3 amazon-web-services terraform terraform-provider-aws
我正在尝试使用 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
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这会导致:
错误:“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
Run Code Online (Sandbox Code Playgroud)
该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
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我会质疑为什么要在此处替换默认 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
}
}
Run Code Online (Sandbox Code Playgroud)
您也可能会受益于使用数据源来选择您的安全组和AMI,而不是为它们传递不透明的 ID。这使他们能够更加自我记录。
| 归档时间: |
|
| 查看次数: |
3028 次 |
| 最近记录: |