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

aws_network_interface.private_ips and aws_network_interface.private_ips_count act in an unexpected way #996

Closed
aschepp opened this issue Jun 28, 2017 · 3 comments
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.

Comments

@aschepp
Copy link

aschepp commented Jun 28, 2017

Terraform Version

Terraform v0.9.8

Affected Resource(s)

  • aws_network_interface

Terraform Configuration Files

resource "aws_network_interface" "interface1" {
	private_ips = [ "${var.ip1}", "${var.ip2}" ]
}

resource "aws_network_interface" "interface2" {
	private_ips_count = 2
}

output "primaryIP" {
  value = "${aws_network_interface.interface2.private_ips[0]}"
}

output "secondaryIP" {
  value = "${aws_network_interface.interface2.private_ips[1]}"
}

Expected Behavior

  • The interface 1 should have two IPs, with ip1 being the primary IP and ip2 being the secondary IP.
  • The interface 2 should have 2 IPs total assigned to it.
  • The output primaryIP should have the primary IP of the interface 2.
  • The output secondaryIP should have the secondary IP of the interface 2.

Actual Behavior

  • Interface 1 will have ip1 and ip2 assigned in an undetermined order. This is because private_ips is a set with string hash as sorting.
  • Interface 2 will have 3 IP assigned to it, one primary and two secondary IPs. The parameter should be renamed to secondary_private_ips_count.
  • The outputs primaryIP and secondaryIP return the IPs in an undetermined order, because again, private_ips is a set with string hash as sorting.

Workaround

As there is no way to reliable get the secondary IP assigned to the interface, you have to use something like this:

resource "aws_network_interface" "interface2" {
	private_ips_count = 1
}

output "primaryIP" {
  value = "${aws_network_interface.interface2.private_ip}"
}

output "secondaryIP" {
  value = "${replace(join(",",aws_network_interface.interface2.private_ips),"/(^|,)${aws_network_interface.interface2.private_ip}(,|$)/", "")}"
}

Possible Fixes

  • Use a List instead of a Set in aws_network_interface.go to store private_ips.
  • Or do not include the primary ip in private_ips, as it's available as private_ip and rename private_ips to secondary_private_ips.
  • Rename private_ips_count to secondary_private_ips_count to make it less confusing.

References

Some of these issues have already been mentioned in #836, but I wanted to extend it.

@jpbuecken
Copy link

  • Rename private_ips_count to secondary_private_ips_count to make it less confusing.

At least that has been documented now:
https://www.terraform.io/docs/providers/aws/r/network_interface.html#private_ips_count

private_ips_count - (Optional) Number of secondary private IPs to assign to the ENI. The total number of private IPs will be 1 + private_ips_count, as a primary private IP will be assiged to an ENI by default.

Maybe the behavior described changed, because of
#8353

@github-actions
Copy link

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

@github-actions github-actions bot added the stale Old or inactive issues managed by automation, if no further action taken these will get closed. label May 13, 2021
@github-actions
Copy link

github-actions bot commented Jun 1, 2022

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 Jun 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.
Projects
None yet
Development

No branches or pull requests

4 participants