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 Output IP not match #9277

Closed
garyjuano opened this issue Jul 9, 2019 · 6 comments · Fixed by #17846
Closed

AWS Network Interface Output IP not match #9277

garyjuano opened this issue Jul 9, 2019 · 6 comments · Fixed by #17846
Assignees
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@garyjuano
Copy link

garyjuano commented Jul 9, 2019

I noticed weird output behavior using aws_network_interface output

Here's my sample code below

resource "aws_network_interface" "testinterface" {
subnet_id ="subnet-xxxx"
private_ips_count = 2
tags = {
Name = "testing-only"
}
}

output "private_ips" {
value = "${aws_network_interface.testinterface.private_ips}"
}

Actual Output:
private_ips = [
"10.0.1.1",
"10.0.1.2",
"10.0.1.3",
]
Above output is correct

But when i changes the private_ips_count = 1 and run terraform apply command again. It still showing the previous output IP.

Actual Output:
private_ips = [
"10.0.1.1",
"10.0.1.2",
"10.0.1.3",
]

My expected should something like this(2 ips):
private_ips = [
"10.0.1.1",
"10.0.1.2",
]

Thanks,

@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Jul 9, 2019
@aeschright aeschright added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jul 11, 2019
@jpbuecken
Copy link

Same issue if you increase private_ips_count.

If you run terraform apply again the output is updated.

It looks like
aws_network_interface.testinterface.private_ip is not refreshed after private_ips_count has been changed.

And in terraform plan the following output may be useful, add (known after apply) to private_ips

      ~ private_ips       = [
            "10.18.82.30",
            "(known after apply)",
            (known after apply)
        ]
      ~ private_ips_count = 0 -> 2
        security_groups   = [
            "sg-08bcca43e47808c18",
        ]

Today with terraform 0.12.3 and aws provider 2.21:

       private_ips       = [
            "10.18.82.30",
        ]
      ~ private_ips_count = 0 -> 2
        security_groups   = [
            "sg-08bcca43e47808c18",
        ]

@cpalmer9
Copy link

cpalmer9 commented Dec 9, 2019

Seeing same issue with Terraform v0.12.17 and provider.aws v2.41.0.
Basically, if you change the private_ips_count value on an existing aws_network_interface, it doesn't get refreshed for the apply and any variables that depend on that value are therefore incorrect. The ENI does get modified in AWS, it's just that Terraform doesn't seem to reflect that.
If you refresh after the apply, Terraform will be correct. Unfortunately for me, I needed the complete data for other resources during the apply.

@bflad bflad added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 9, 2020
@bflad
Copy link
Contributor

bflad commented Sep 9, 2020

To properly trigger the private_ips attribute to show as unknown (and therefore expected to have reference updates) when the private_ips_count argument is updated, a CustomizeDiff function can be added to the aws_network_interface resource using customdiff.ComputedIf(), e.g.

		CustomizeDiff: customdiff.Sequence(
			customdiff.ComputedIf("private_ips", func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
				return diff.HasChange("private_ips_count")
			}),
		),

For acceptance testing this functionality, the TestAccAWSENI_PrivateIpsCount test steps can be updated to check the state private_ips.# value for updated amounts.

@rick-masters
Copy link
Contributor

@bflad
Thanks for pointing out ComputedIf! I was really stuck without it but didn't know it until I stumbled upon your comment.

Most unfortunately, because the names private_ips and private_ips_count overlap, the SDK mistakenly deletes the pending change to private_ips_count. See hashicorp/terraform-plugin-sdk#715 just filed. That bug causes this example and pretty much only this example to fail (i.e private_ips_count has no effect). That's bad luck man.🤪

@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
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
7 participants