terraform > forces new resource on security group

僤鯓⒐⒋嵵緔 提交于 2020-04-10 20:26:34

问题


I've got a very simple piece of Terraform code:

provider "aws" {
  region = "eu-west-1"
}

module ec2 {
  source = "./ec2_instance"
  name = "EC2 Instance 1"
} 

where the module is:

variable "name" {
    default = "Default Name from ec2_instance.tf"
}

resource "aws_instance" "example" {
  ami = "ami-e5083683"
  instance_type = "t2.nano"
  subnet_id = "subnet-3e976259"
  associate_public_ip_address = true
  security_groups = [ "sg-7310e10b" ]
  tags {
    Name = "${var.name}"
  }
}

When I first run it I get this output:

security_groups.#:            "" => "1"
security_groups.1642973399:   "" => "sg-7310e10b"

However, the next time I try a plan I get:

  security_groups.#:            "0" => "1" (forces new resource)
  security_groups.1642973399:   "" => "sg-7310e10b" (forces new resource)

What gives?!


回答1:


You are incorrectly assigning a vpc_security_group_id into security_groups instead of into vpc_security_group_ids. Change
security_groups = [ "sg-7310e10b" ]
to
vpc_security_group_ids = [ "sg-7310e10b" ] and everything will be ok.



来源:https://stackoverflow.com/questions/51496944/terraform-forces-new-resource-on-security-group

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!