为什么已经创建的实例被删除并重新创建?

时间:2019-08-07 15:30:15

标签: terraform-provider-aws

我已经使用Terraform 0.12.6创建了资源。但是,在不对代码进行任何更改并进行“地形应用”的情况下,该过程希望销毁现有的EC2并对其进行重建。我想知道为什么这样做以及下面的错误之处。

resource "aws_instance" "web_ui" {
  count                       = 2
  ami                         = data.aws_ami.ami.id
  instance_type               = var.type_m5lg
  associate_public_ip_address = false
  key_name                    = var.key_name
  security_groups             = [var.vpc_security_group_ids, var.sg_devops, var.sg_common]
  subnet_id                   = (data.aws_subnet.subnetid)[count.index].id
  root_block_device {
    delete_on_termination = true
  }
  ebs_block_device {
    device_name           = "/dev/sdb"
    volume_size           = "200"
    volume_type           = "gp2"
    delete_on_termination = true
  }
  tags = "${merge(
    local.common_tags,
    map(
      "Name", "${var.name}-${var.prog}-${var.env}${count.index + 1}-${var.ec2_name_web}-use1.xyz.com"
    )
  )}"
}

1 个答案:

答案 0 :(得分:0)

更改 security_groups = [var.vpc_security_group_ids,var.sg_devops,var.sg_common] TO vpc_security_group_ids = [var.vpc_security_group_ids,var.sg_devops,var.sg_common] 解决了这个问题。

基于@ stack72 hashicorp / terraform#7853的评论