![](/img/trans.png)
[英]How to attach existing EC2 instances to auto scaling group in terraform?
[英]Terraform add existing security group to new auto scaling ec2 group
我想將 VPC 中定義的現有安全組添加到 EC2 Auto Scaling 組。 沒有定義 LB。 此示例暫時創建了一個 EC2 實例。
Terraform 文檔顯示這對於使用 sg_attachment 的 EC2 實例是可能的
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:
network_interface_id = aws_autoscaling_group.bastion.primary_network_interface_id此對象沒有參數、嵌套塊或名為“primary_network_interface_id”的導出屬性。
我看過自動縮放組附件 - https://www.terraform.io/docs/providers/aws/r/autoscaling_attachment.html
但這根本不是指安全組。
當然 - 我可以隱式指定一個具有所有相同規則的新安全組,或者只是聲明一個 ec2 實例。 但是在控制台上創建自動縮放組時 - 您可以選擇導入現有的安全組。 所以我想認為 terraform 有一個等價物。
看來我忽略了以前的設置:
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,修復了該問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.