-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Network Interface private_ips in different order #169
Comments
This is a reapply of the old fix that fixes issue hashicorp#169
Need this please |
Yep I just hit this while attempting to build a SQL availability group. |
Yes, same for me. It gets a bit weird:
produces:
but
gives correct order:
|
I just discovered this behaviour when creating a number of private IPs on an ENI. The ordering of private IP addresses in the Terraform state for I ran a test to demonstrate how the ordering of the resource "aws_network_interface" "test" {
subnet_id = "${local.subnet_id}"
security_groups = ["${local.sg_id}"]
private_ips_count = 5
}
output "eni_list_of_private_ips" {
value = "${aws_network_interface.test.private_ips}"
} Check ordering of private_ips list in Terraform state and output:
Compare with ordering returned by AWS API:
{
"NetworkInterfaces": [
{
"NetworkInterfaceId": "eni-fffffffffffffffff",
"InterfaceType": "interface",
"Groups": [
{
"GroupName": "default",
"GroupId": "sg-ffffffff"
}
],
"SubnetId": "subnet-ffffffff",
"PrivateIpAddress": "10.80.161.65",
"PrivateIpAddresses": [
{
"PrivateIpAddress": "10.80.161.65",
"Primary": true
},
{
"PrivateIpAddress": "10.80.162.115",
"PrivateDnsName": "",
"Primary": false
},
{
"PrivateIpAddress": "10.80.162.20",
"PrivateDnsName": "",
"Primary": false
},
{
"PrivateIpAddress": "10.80.160.6",
"PrivateDnsName": "",
"Primary": false
},
{
"PrivateIpAddress": "10.80.161.153",
"PrivateDnsName": "",
"Primary": false
},
{
"PrivateIpAddress": "10.80.163.205",
"PrivateDnsName": "",
"Primary": false
}
]
}
]
} The ordering of private IPs in the Terraform state does not match the ordering returned by the AWS API. The order returned by AWS API matches what is displayed in the AWS console, and keeps the private IP address as the first IP in the list. The order of Change interface count from 5 to 10: resource "aws_network_interface" "test" {
subnet_id = "${local.subnet_id}"
security_groups = ["${local.sg_id}"]
private_ips_count = 10
} Check ordering in Terraform state and output again:
5 new IPs have been added, but have been scattered through the existing list. The order of the existing IPs is maintained, but the new IP addresses are spread through the list. However, the ordering of the private IPs returned by the AWS API is much more predictable. The existing list of private IPs are at the start of the list, with the new 5 IPs added to the end of the list:
{
"NetworkInterfaces": [
{
"NetworkInterfaceId": "eni-fffffffffffffffff",
"PrivateIpAddress": "10.80.161.65",
"Groups": [
{
"GroupName": "default",
"GroupId": "sg-ffffffff"
}
],
"SubnetId": "subnet-ffffffff",
"InterfaceType": "interface",
"PrivateIpAddresses": [
{
"Primary": true,
"PrivateIpAddress": "10.80.161.65"
},
{
"PrivateDnsName": "",
"Primary": false,
"PrivateIpAddress": "10.80.162.115"
},
{
"PrivateDnsName": "",
"Primary": false,
"PrivateIpAddress": "10.80.162.20"
},
{
"PrivateDnsName": "",
"Primary": false,
"PrivateIpAddress": "10.80.160.6"
},
{
"PrivateDnsName": "",
"Primary": false,
"PrivateIpAddress": "10.80.161.153"
},
{
"PrivateDnsName": "",
"Primary": false,
"PrivateIpAddress": "10.80.163.205"
},
{
"PrivateDnsName": "",
"Primary": false,
"PrivateIpAddress": "10.80.163.0"
},
{
"PrivateDnsName": "",
"Primary": false,
"PrivateIpAddress": "10.80.162.244"
},
{
"PrivateDnsName": "",
"Primary": false,
"PrivateIpAddress": "10.80.161.105"
},
{
"PrivateDnsName": "",
"Primary": false,
"PrivateIpAddress": "10.80.163.74"
},
{
"PrivateDnsName": "",
"Primary": false,
"PrivateIpAddress": "10.80.160.111"
}
]
}
]
} The problem I can foresee is that if I assign elastic IPs to these private IPs like this: variable "eip_count" {
default = "5"
}
resource "aws_eip" "test" {
count = "${var.eip_count}"
vpc = "true"
}
resource "aws_eip_association" "test" {
count = "${var.eip_count}"
allocation_id = "${aws_eip.test.*.id[count.index]}"
network_interface_id = "${aws_network_interface.test.id}"
private_ip_address = "${aws_network_interface.test.private_ips[count.index]}"
} If the number of private IPs on the ENI increases, then the list of elastic IPs |
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! |
In practice, the API does seem to return the private IPs in a specific order. The web console also seems consistent with it. That said, nowhere does it say that they will be returned in a specific order. The EC2 API even goes to call it That said, in Cloudformation, one of the outputs for a On the other hand, changing the type in terraform from set to list would also certainly break a lot of things so I'm not really sure what a good option is. A related PR is also still open #1672 with some discussion related to ordering but it looks like they're moving towards an alternate solution to the problem. |
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! |
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. |
This issue was originally opened by @Shaiou as hashicorp/terraform#6750. It was migrated here as part of the provider split. The original body of the issue is below.
Hi there,
I'm running into some issue when creating a network interface, I specified a list of private_ips and made sure the one I wanted as primary was listed first, however it does respect that order and the second one appears as primary:
Here's my ressource:
And the output of the terraform show after the apply:
Can you help ?
The text was updated successfully, but these errors were encountered: