我希望将VPC中定义的现有安全组添加到EC2自动缩放组中。没有定义LB。此示例目前只创建一个EC2实例。
Terraform文档显示,对于使用EC2的sg_attachment实例来说,这是可能的
resource "aws_network_interface_sg_attachment" "bastion" {
security_group_id = var.sg_id
network_interface_id = aws_autoscaling_group.bastion.primary_network_interface_id
}但是我得到了以下错误,可能是因为我使用的是自动缩放组:
错误:不支持的属性
在......\modules\ec2_auto_scaling_group\bastion.tf第51行中,在资源"aws_network_interface_sg_attachment“”堡垒“中: 51:
aws_autoscaling_group.bastion.primary_network_interface_id = network_interface_id
该对象没有名为"primary_network_interface_id“的参数、嵌套块或导出属性。
我见过自动标度组附件- https://www.terraform.io/docs/providers/aws/r/autoscaling_attachment.html
但这根本不是指安全组织。
当然,我可以使用所有相同的规则隐式地指定一个新的安全组,或者只是声明一个ec2实例。但是在控制台上创建自动标度组时,您可以选择导入现有的Security。所以我想认为地形有一个等价物。
发布于 2020-01-07 13:18:49
我似乎忽略了以前的设置:
resource "aws_launch_configuration" "bastion" {
# Launch configuration can't be updated, (provisioning)
# in order to update the resource will be destroyed and rebuilt
name_prefix = var.bastion_name_prefix
image_id = data.aws_ami.RHEL_77.id
instance_type = var.bastion_instance_type
key_name = aws_key_pair.bastion.key_name
associate_public_ip_address = true
enable_monitoring = false
security_groups = [var.vpc_main_sg_id,aws_security_group.bastion.id]
lifecycle {
create_before_destroy = true
}
}在aws_launch_configuration中添加一个安全组,解决了这个问题。
https://stackoverflow.com/questions/59628842
复制相似问题