-
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
Dependency ordering issue when aws security groups has multiple ingress CIDR blocks #670
Comments
I think this is because AWS reorders them when it returns. We should probably treat them as a set and not a list to fix this. |
@armon I tested this and that is exactly the case. But I was thinking if it would make sense to start using a set on all places where the API could return a differently ordered list then you have in your config. Personally I was thinking to sort the list before reading/writing it from/to config/state. This would also prevent these kinds of issues... But not sure if that would be a good approach? /CC @mitchellh |
@svanharmelen Hmm sorting may be a better call for simple list of strings. My worry is that the switch to set is not backwards compatible. |
@armon the config would stay the same and the state would be converted (automatically done by the existing code already) without any issues. But it would mean updating and tweaking all locations where this (moving from a list to a set) is applicable which could be a little more work to test and work through. Next to that it would mean that the use cases for a list would actually become less clear as you had to take this ordering issue into account when creating the resource schema/code. So I think just ordering the list (only when the elements are int's or strings) would be a pretty nice and relative clean solution... |
I think conceptually a set is correct. A sorted string list "works" and we've done that before, but a set "just works" because it is correct (you don't do any extra work). As a user, there will be a backwards incompatible issue here, and that is something to think about as well. I think what @armon brought up today is important: we need a way to be able to make schema changes like this and migrate to the new version. But, that is the topic of another issue. Given we don't have such a system, I'm supportive of @svanharmelen's idea of just sorting the strings... |
I fully agree that conceptually a set is correct... So maybe we shouldn't go the route of sorting lists after all. If your concerns are only about backwards compatibly, I don't see that issue. I did some quick tests and think there will be no impact. Let me do a quick PoC (guess will be tomorrow) with the use case of issue #657 to confirm my thoughts. |
@mitchellh @armon see PR #677 for an example which actually works flawless on an existing config and state file. I tested this with this config:
Which just keeps updating every time you apply, until you merge this PR and then its done updating. After a So there is absolutely no backwards compatibility issue here, it's just a few lines of code that need to be changed in the providers having this issue... |
👍 let's go down that route. |
Cool! Working on that PR then (commenting). |
Well... In the end this is really simple, but the fix will not be backwards compatible... Since the AWS API merges all rules that have the same
By doing this you are able to read back the info from AWS and match that info to your config. With the current hash function each rule can have the same values for So if you then read back the info from AWS and get the info from those two rules back as one rule, there is no way TF can match that back to your config in a sane way. But like I said, this would be a backwards incompatible change for the @mitchellh what do you think about this solution? Any other thoughts? |
That would mean that we 'll only get a big diff on tfstate and all the breakage would be an issue if across an organisation different terraform cli versions are used, but then again the result would only be this ping pong between previous hash method and suggested current method producing a plan that would update all Let's not wait for 0.4.0 please |
Well... That... And if you do have multiple rules defined in a single resource that have the same Once a certain hash is added to your set, the next time you try to add a value with the same hash it's ignored and not actually added to the set (which makes sense of course). So people having such a config will need to adjust their config by merging the separate rules into one rule per |
Woah, good point. And that explains some other bug, I will post it later on. |
@mitchellh would love to get your take on this one... Would be nice to be able to close this one, but I fail to see a solution without impact... |
Couldn't you just split out the return values from AWS API into a resource having |
@brycekahle not sure if I'm following you correctly, could you elaborate and maybe give a small pseudo example? At first side I don't see how you would want to do this without a change to either the schema or the hash function. |
@svanharmelen Since you can't create an ingress with both |
@brycekahle I think I get your point, but as far as I can tell that isn't related to the issue we need to solve here. The problem here is that the AWS API merges all rules that have the same And since these (the So even if you make it so that you can only specify either |
@svanharmelen That all makes sense. I do think the current hash function is correct and doesn't need to be changed. I think the issue is the intermediate structures being generated from the config and from the EC2 API. My understanding is the following would need to happen:
Perhaps there is something I am missing about how terraform internals work? |
@brycekahle I did have quick a look at an approach like that a few ago, but I couldn't figure out a sane way to do that in the current code base. I think quite a few things would need to be changed/refactored in the core components of TF and I (personally) don't think that would be worth it as this is the only resource (AFAIK) that has this kind of issue. So in my opinion this is just an error in the resource schema definition and/or hash function... |
@svanharmelen I'll see if I can come up with a PR that only changes this resource provider. |
This actually happened to me but when using |
Could the Seems like that would allow the merged security_group objects replies from AWS CLI to be separated correctly. Pseudo-code for the tag value creation:
|
so is this fixed or what? im on .0.6.3 and i have the problem with aws security groups constantly changing during an apply, due to the ordering issue |
+1 |
as of 0.6.6 this does not appear to be fixed. Is there something I can do to help? |
Hello all – I'm following up here after some time, apologies for the silence here. This block does not trigger constant plan changes: ingress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["10.0.0.1/32", "10.0.0.5/32", "10.0.0.3/32", "10.0.0.2/32", "10.0.0.4/32"]
} The ordering of the The problem in the original message is two distinct The short of it is that two Is there a specific need to have them in separate blocks? |
I'm on version 0.6.4 and seeing a similar issue. I have the following
Every single time I run
Is this an issue of having multiple ingress blocks with identical ports and protocols or something different? |
@brikis98 I ran into this issue as well, but with a different Terraform resource. The following fix resolved it me. Does this apply to your issue?
Note the difference in the |
@josh-padnick: No, I don't think that's the issue. The
|
@scalp42: You're right, it was the "TCP" vs "tcp" thing. Thank you! |
I'm going to close this for now. This issue has expanded to mention 2 or 3 things, all of which I believe are resolved now. If not, please let me know or make a separate issue. Thanks! |
I'm still seeing this in 0.6.9 with a security group that has multiple ingress (from self and vpc cidr) for the same port/protocol (setting up a "default" sg for the peered vpc so all traffic from the primary is allowed)
|
After digging some more I found #2843 and when I normalize my rule to have both self and the cidr, the diff comes back clean. The normalization rules should probably be added to the docs for aws_security_group if this can't be fixed |
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. |
Hi,
The below code causes terraform plan to always switch the order of the cidr_blocks
-S.
The text was updated successfully, but these errors were encountered: