Skip to content
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

Fixes #836 - correctly assign primary private IP for aws_network_instance when private_ips are specified #1749

Closed
wants to merge 5 commits into from

Conversation

nbaztec
Copy link

@nbaztec nbaztec commented Sep 26, 2017

Details
This PR fixes #836

Before
The primary_ips were stored as a Set with no guaranteed order. So the primary IP would be randomly assigned from the set, while the primary_ip field would be ignored.

After
The module now respects and sets the primary_ip field when primary_ips is also defined. If not, a random IP is made primary from primary_ips.

@radeksimko radeksimko added the enhancement Requests to existing resources that expand the functionality or scope. label Sep 27, 2017
@nbaztec
Copy link
Author

nbaztec commented Oct 27, 2017

Anyone watching this?

@radeksimko radeksimko added the size/L Managed by automation to categorize the size of a PR. label Nov 15, 2017
@thallam08
Copy link

Any idea of when this is going to be merged and available? It's biting me at the moment. Is there a workaround?

@nbaztec
Copy link
Author

nbaztec commented Nov 20, 2017

We're currently running a custom built binary from the PR. Would be good if someone actually reviewed/merged it so we can use drop our custom plugin in favor or official plugin.

@Ninir
Copy link
Contributor

Ninir commented Nov 20, 2017

Hi folks,

@radeksimko wrote a comment regarding the same work in #1672

@nbaztec : As this work is the same as in the other PR (but a bit younger) can you read this comment and answer in the other PR so that we centralize the work?

Thanks!

@Ninir Ninir added breaking-change Introduces a breaking change in current functionality; usually deferred to the next major release. waiting-response Maintainers are waiting on response from community or contributor. labels Nov 20, 2017
@thallam08
Copy link

thallam08 commented Nov 21, 2017

I notice this is marked as "enhancement" - it's actually a bug fix. The correct action is to use the first item in the lists of IPs as the primary IP, anything else is incorrect behavior.

@nbaztec
Copy link
Author

nbaztec commented Nov 22, 2017

I'll be replying in #1672 to centralize the work

@nbaztec nbaztec changed the title Fixes #836 - use first private IP as primary for AWS instance Fixes #836 - correctly assign primary private IP for aws_network_instance when private_ips are specified Nov 22, 2017
@nbaztec
Copy link
Author

nbaztec commented Nov 23, 2017

@Ninir please re-flag/re-review the PR.
Thanks.

@nbaztec
Copy link
Author

nbaztec commented Nov 25, 2017

PS: I don't think this could be a breaking change anymore.

@nbaztec
Copy link
Author

nbaztec commented Dec 4, 2017

The PR needs to be reflagged post the changes.

@nbaztec
Copy link
Author

nbaztec commented Jan 16, 2018

@radeksimko Could you please re-review and re-tag the PR. It has undergone some changes as per discussion in #1672

@bflad bflad added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 28, 2018
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Mar 8, 2018
@nbaztec
Copy link
Author

nbaztec commented Mar 8, 2018

Updated with upstream

@curator
Copy link
Contributor

curator commented May 1, 2018

Can we get some eyes on this? The inability to set the primary is really stopping use of terraform in a number of (particularly) non-ephemeral instance cases.

@thallam08
Copy link

thallam08 commented May 2, 2018

@curator What version of the AWS module are you using? I've not had any issues with aws provider 1.16. Could be that I've just been lucky and the order I put the IPs in, matched the hashed order.

@nbaztec
Copy link
Author

nbaztec commented May 2, 2018

@thallam08 that's probably the case, since the code always hashes them and then the order (and the primary IP) depends on the lexical ordering of the hash.

@thallam08
Copy link

@nbaztec Yes, that was the basis of the problem. "Order in" != "Order out" because an unordered list had been used rather than an ordered list.

But I believe that has now been fixed, as I no longer see this issue on the terraform template that I used to have issue with.

Check the version of the AWS module installed in your .terraform/modules directory.

@nbaztec
Copy link
Author

nbaztec commented May 2, 2018

I can't test right now but I still see in master that we are casting from schema.Set which makes it unordered in the first place.

https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_network_interface.go#L122

Maybe I'll test it over this weekend again. Thanks.

@thallam08
Copy link

thallam08 commented May 2, 2018 via email

@curator
Copy link
Contributor

curator commented May 2, 2018

@thallam08 As nbaztec pointed out, 1.16 still produces the issue; right now we're using a fork from way back in the way to deploy systems that have the deterministic requirement for now, but that's not our preferred route obviously. Hopefully an appropriate solution can reach master soon.

@nbaztec
Copy link
Author

nbaztec commented May 2, 2018

We are also using a fork like @curator with the changes contained in this PR. I would be more than willing to work further on this PR if the core team can give it a look.

@thallam08
Copy link

Can this be merged and released? It bit me again today. This time, when I added another IP, it tried to change the primary IP of an interface. AWS does not allow you to change the primary IP of an interface, so the update failed.

@thallam08
Copy link

I've not seen any evidence that this is a breaking change. The current behavior, without this fix, is non-deterministic as it relies on the hash valued of the set for the order. This is a FIX to a significant issue that is breaking the use of multiple IPs on an interface.

@thallam08
Copy link

Can the tags for this be changed?

  • It's a "bug" not an "enhancement"
  • It's not a "breaking change" (well I suppose it does break incorrect behavior)

@nbaztec
Copy link
Author

nbaztec commented Jun 21, 2018

I would agree with @thallam08 - the PR has been update to not be a breaking change but a simple bugfix.
@Ninir

@thallam08
Copy link

@Ninir So how do we get the tags on this changed so they match what this change really is, and then get it included in the next release?

@bganderson
Copy link

+1 Lets get this merged in

@nbaztec
Copy link
Author

nbaztec commented Jul 24, 2018

Does anyone know of an active maintainer that can take a look into it perhaps?

Closing in on a 1 year anniversary :)

@nbaztec
Copy link
Author

nbaztec commented Sep 3, 2018

Merged with upstream for a more up-to-date PR

@nbaztec
Copy link
Author

nbaztec commented Sep 7, 2018

@bflad would you be so kind as to re-label this long standing PR please :)

@sabretus
Copy link

sabretus commented Nov 9, 2018

Need this too. Why this case is ignored?

@simonbrady
Copy link

Any timeline for merging this please? This PR resolves a significant problem in the provider.

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Jan 16, 2019
@yn-academia
Copy link

yn-academia commented Feb 11, 2019

This PR seems wrong, as it's still a breaking change, no? All you want to do is include "private_ip" in the list of "private_ips", and then make sure it's passed up to AWS API.

@nbaztec
Copy link
Author

nbaztec commented Feb 12, 2019

@yn-academia the Amazon API explicitly states the use of private_ip for the primary address and any other secondary addresses within private_ips. In the absence of former it designates the first IP in the list as primary. However we use HashSets within the module, for good reasons, and that makes it impossible to be determinastic in regards to the first element in that list. As such the previous behaviour was that a random IP would be chosen as the primary. This fix makes it determinastic again.

@adrmaas
Copy link

adrmaas commented Feb 20, 2019

@radeksimko @Ninir we have also been bitten by this bug and the documentation as it stands is ambiguous.

Perhaps someone could explain how this is being interrupted as breaking change and enhancement?

@yn
Copy link
Contributor

yn commented Feb 24, 2019

This is a breaking change because users have current infrastructure that was spun up using the existing implementation, and their infrastructure has a random IP assigned as the primary, even when they specified a primary_ip which was then ignored. When they update to a new version of the AWS provider that includes your fix, terraform will want to change the primary IP of their infrastructure. You mark private_ip as ForceNew:true, which means that what terraform will actually want to do is to destroy existing infrastructure and create new infrastructure, but the users' terraform configuration files haven't changed, the only thing that changed was a minor version upgrade of the terraform AWS provider. Sounds like a breaking change to me.

Yes, it breaks configuration that relies on the behavior of an existing bug, and yes, that's unfortunate, but there are probably hundreds of production systems that rely on this now, and you have to think about them.

If you want to make this not a breaking change, you have to do something much uglier - you'd have to keep all existing implementation as is, and then add a new field called actual_private_ip or something like that which does what you want. Since no one's existing infrastructure has actual_private_ip in the configuration, you are more likely to get this merged. If you do go this route, you should probably open new PR, rather than continue building on this one.

The ultimate correct behavior is the one that you are proposing in this PR, but I'd imagine that a breaking change would only be allowed in across a major version upgrade of the terraform AWS provider.

Anyway - I don't work for HashiCorp, I am just a random user of terraform, so this entire comment may be completely wrong, but that's what I would do if I was running a project like this.

@nbaztec
Copy link
Author

nbaztec commented Feb 24, 2019

While what you say is true regarding the fix and it reassigning a new IP if a mismatch occurs, in most general cases the IPs are precomputed due to an automation pipeline and a determinastic IP would've been expected. In the absence of that probably users would've opted to terraform output and exported the IP to enable further usage. For most cases, assuming proper automation, it shouldn't cause much pain to have this fix, however, for some users a manual approach would certainly be required. Personally for me, that may or may not be a reason for a major upgrade. But so far, the maintainers have failed to comment on that as well and no milestone label has been provided to boot.

As such, I would defer any further development or speculative discussion until one of the maintainers share their view on the bug/approach.

@nbaztec
Copy link
Author

nbaztec commented Aug 3, 2020

closing due to lack of a decision.

@nbaztec nbaztec closed this Aug 3, 2020
@ghost
Copy link

ghost commented Sep 3, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Sep 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking-change Introduces a breaking change in current functionality; usually deferred to the next major release. enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service. size/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sort private ips for an AWS instance in Terraform