Currently if you add a security group in AWS terraform reports the following and a new resource is forced.
security_groups.#: "1" => "2" (forces new resource)
security_groups.3297643359: "sg-XXX" => "sg-XXX" (forces new resource)
security_groups.966748175: "" => "sg-XXX" (forces new resource)
It would be nice to be able to add a security group to a list of security groups (not changing any existing SG's) without having to recreate the server.
If you are using ec2 classic then that is the only way to apply additional SGs. If you are on VPC then this is definitely a modification I would like to see to terraform since AWS VPC allows you to add/remove SGs on the fly.
Yes sorry, forgot to mention this was for a VPC.
This is another bug reported somewhere. We're close to finally fixingthis but please track that bug.
@mitchellh can that issue be referenced here? This bug seems to occur as of v0.6.8. I have an existing aws_instance
resource with 1 security group under security_groups
, and when I try to add a second one it tells be that the existing aws_instance
resource will be deleted because the additional security group forces new resource.
Hello @cleung2010 – for instances in a VPC, use vpc_security_group_ids
instead of regular security_groups
. Using the vpc_
version will allow you to add/remove security groups without recreating the instance.
Thanks!
Sorry for the noise, but just wanted to say thanks so much for this. I've been banging my head as all my instances have been being force-recreated. I missed it in the docs. Terraform rawks.
Thanks! It helped a lot for beginner in terraform like me :)
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Hello @cleung2010 – for instances in a VPC, use
vpc_security_group_ids
instead of regularsecurity_groups
. Using thevpc_
version will allow you to add/remove security groups without recreating the instance.Thanks!