-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All vpc_security_group_ids
being removed when updating instance Security Groups
#9043
Comments
@scottgeary hi there! I am very sorry that you are affected by this! We are having a look, as this is a very hard to catch issue, as I personally could not reproduce it successfully. I will keep you posted once we find out what might be creeping there! |
I walked @stack72 through this on my machine, but we still couldn't figure out why. Does not appear to be an API-limit-related issue. |
@scottgeary After two days of head banging I just realized that I'm having this exact same problem. Mine manifested when I tried to add 1 SG to an existing array of 4. Repeated applies flip-flop between just the new 1 and just the original 4. When doing a delete it's the same behavior except aws won't let you send it 0 SGs. Otherwise yours would flip-flop too between setting your instance to 4 then 0 then 4 then 0. I believe it's yet another ignore_changes bug. I had just recently added ignore_changes['user_data'] to my resource just like above. I thought it was working now (to be fair, it does ignore the user_data now) :( One can reliably reproduce the issue like below. First, create an instance:
Then, change user_data "foo" to "bar" and also add a new SG to the array.
a plan will give you strange output:
Note how the plan doesn't show the expected
entries. This is bad :)
The action should be all 3 groups (GroupId.1 and GroupId.2 and GroupId.3)
If you then remove the ignore_changes line and run a plan at this point, you'll get a plan that of course wants to recreate the instance, but the sg change will at least look correct:
I of course added ignore_changes recently because I needed to update my user_data without reprovisioning lots of nodes, thus I'm now stuck in a state where I get to pick between adding a SG and reprovisioning lots of nodes :( I will add that as a workaround, you can manually attach the new SG to your instance via console/cli and Terraform will not complain about it. Probably works for removing one also. Anyway, seems ignore_changes needs to be examined further. Hope this helps! |
Just to add a bit more proof, I played a bit last night with eval_diff.go and tried (around line 240) :
running this against my earlier example resource results in the correct plan (didn't try applying). This suggests that one approach might be to make sure we're not deleting diff attributes that we care about in this particular run. Note that if I run a plan using the above hacked TF against other resources that have a pending recreate due to user data, are blocked from doing so by ignore_changes, but have no other changes (vpc_security_group_ids or otherwise), I get a useless diff in my plan for all of them, e.g.
Looking further it seems the problem is a bit earlier where we do:
problem being that this ends up deleting part of our diff, e.g. A => A, since that's matched by .Empty(). This is likely a problem for all list types of attributes. Seems that we should look for the existence of a parent counter key, e.g. "vpc_security_group_ids.#" and if it's changing, we should exclude all child entries from the ignorableAttrKeys map. |
What we actually need to do is check if any siblings are changing. Potential fix in #9791 |
I'm seeing this bug too, I'm adding a new security group to the instance and the original 2 are disappearing and it everytime I run plan it flips flops back and forth.
then
|
I'm seeing this as well. Earlier in the week it was that a vpc_security_group_ids entry was not being removed, and so I removed it via console. The plan output looked much like ekristen's comment. This was relatively benign and so I didn't bother to enter an issue on it. Today however, this same issue had some destructive behavior. It removed all SG except the one I was adding; luckily I was doing this on a dev machine. But I must proceed with modification of SG across many more instances. Early warning from plan:
Count goes to 4 so I'm sure everything will be OK and so I apply.
Close enough, right? Probably just some display error. Then I validate in console and the only SG attached to the instance is sg-asdfasdf, so I begin to cry again. I wipe my face and then plan:
Hooray. This looks more correct. I mean, it isn't showing
Console reveals that I again have only 3 SG and the new one isn't being put into place. It is too early in the day to start drinking. Maybe I can make a workaround. Advice appreciated. |
@ekristen @Gary-Armstrong can you guys test my fix from #9791 ? Maybe it'll get more traction if it works for you. |
Update:
Using this HCL where the 2 SG are completely unrelated, when I do a plan/apply cycle it will switch to whichever SG isn't applied to the instance.
Just by doing an apply, it will flip back and forth between the two SG. |
More experiments reveal the pattern (in my case) is to replace existing list items with new list items, rather than merge the list and replace existing list items with new merged list items. |
@br0ch0n If it involves compiling a new terraform, I'll not participate. I have to manually change SG assignments on many instances today. |
Still happens in 0.8.6 |
just got bit by this bug as well today. Added a new security group to my vpc_security_group_ids list and it removed all existing security groups from my instance and only added the new security group. |
Thanks for the research here. I've reproduced this issue with the following gist and instructions above: I'm relabeling this as a |
Hey all – looks like this should be patched up with #12897 , will go out in the next release |
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. |
When trying to modify AWS Security Groups on an already Terraformed EC2 instance, it seems to forget about all existing SGs (even though they appear in the statefile), and the
plan
output initially looks legit.We originally found this issue, when trying to add a brand-new SG. Terraform removed all existing SGs (and caused some chaos!), but successfully added the new one. We've since reduced the problem down to just removing an existing SG, or somewhere parsing the existing SGs from the
vpc_security_group_ids
field.In the following example:
ganglia-a
AAAAAA
,BBBBBB
,CCCCCC
, &DDDDDD
BBBBBB
.4=>3
Terraform Version
Terraform v0.7.4
Affected Resource(s)
Terraform Configuration Files
Existing Statefile showing existing 4 SGs:
Existing Terraform file:
Actual change we're trying to apply (removal of
BBBBBB
)Terraform Plan
Debug Output
https://gist.github.com/scottgeary/67a7584bffdeeb672425cf6d1092c5c9
Expected Behavior
aws_security_group.BBBBBB
being removedActual Behavior
Steps to Reproduce
terraform plan
terraform apply
Important Factoids
References
The text was updated successfully, but these errors were encountered: