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

Sort private ips for an AWS instance in Terraform #836

Closed
hashibot opened this issue Jun 13, 2017 · 7 comments · Fixed by #17846
Closed

Sort private ips for an AWS instance in Terraform #836

hashibot opened this issue Jun 13, 2017 · 7 comments · Fixed by #17846
Assignees
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@hashibot
Copy link

This issue was originally opened by @Joe6547654 as hashicorp/terraform#15173. It was migrated here as part of the provider split. The original body of the issue is below.


Hi, I am using terraform to create an instance with multiple ips in AWS. I specified a list of private_ips in the network interface block and I made sure the one I wanted as primary ip was listed first on the list, however it does not respect that order when I create the instance in AWS. Order doesn't change even when when I change the ips around. I also tried setting with private_ip for the primary ip and private_ips for secondary ips, but it doesn't work.

Terraform Version: 0.9.6

Affected Resource(s)

  • aws_instance
  • aws_network_interface

Terraform Configuration Files

resource "aws_network_interface" "test" {
	subnet_id = "subnet-xxxxxxx"
	private_ips = ["172.24.3.249", "172.24.3.250", "172.24.3.5", "172.24.3.9", "172.24.3.13"]
}
resource "aws_instance" "test" {
	ami = "ami-xxxxxxxx" 	
	instance_type = "m4.2xlarge"
	key_name = "name"
	network_interface {
	network_interface_id = "${aws_network_interface.test.id}"
	device_index = 0
	}
}

Expected Behavior

The first ip address on the list will appear as the primary ip, and the rest as the secondary ips.

Actual Behavior

"172.24.3.5" becomes the primary instead of the first ip on the list. It does not change even if we switch the order of the ips.

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

@nbaztec
Copy link

nbaztec commented Oct 12, 2018

#1749 fixes this behavior but hasn't received any attention since more than a year.

@OneSpecialPeg
Copy link

How is such a fundamental use case still an issue?

This problem has cost us thousands as we have to use larger instance types that support more nics/ips as we can only assign a single ips on the primary nic when it needs to be known.

We expected it would only be temporary but have now been doing it for over a year. It is frustrating.

@jpbuecken
Copy link

How is such a fundamental use case still an issue?

This problem has cost us thousands as we have to use larger instance types that support more nics/ips as we can only assign a single ips on the primary nic when it needs to be known.

We expected it would only be temporary but have now been doing it for over a year. It is frustrating.

With terraform you can already have multiple IPs on the primary nic, just build your instance via port as shown in the bug description. To avoid this bug, start with one ip, then build the instance, then add other IPs.
If you use dhcp, see my bug report #6125

Be aware that the number of ips is restricted by AWS, that is not a terraform bug:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerENI

@OneSpecialPeg
Copy link

OneSpecialPeg commented Feb 27, 2019

That’s fine if you are manually creating your instances but if you have built an automated pipeline and give developers ability to spin up their own evironements then things aren’t so simple.

I am very much aware that nic/ip limit is from AWS and not Terraform. To clarify; as I require a known primary ip for the load balancer I am spinning up I cannot add my additional ips to the primary nic therefore I have to use a larger instance type than desired to get my required number of ips.

@dragon788
Copy link

It might be possible to do something hacky like use the output from an initial template that creates the original interface to import into another module and reference that existing interface with a larger set of IPs (the primary plus secondaries), but I haven't attempted that yet and you'd need to figure out whether to append it to the list/set or if you would need to redefine the primary as well as the secondaries so it wouldn't drop the initial/primary IP. This may also lead to "flapping" if re-running the initial module removes the extra IPs each time.

@github-actions
Copy link

This functionality has been released in v3.74.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
7 participants