Closed Dogers closed 5 years ago
Interestingly after a little bit of playing it seems that reducing the number of private IPs works, so this may just be a validation order issue?
I have uncovered some relevant additional details that may help uncover this issue.
tl;dr: It's definitely a bug. The problem occurs when going from private_ip_count = 0
(or not setting private_ip_count
at all) to a higher number. If you start with 1
and go to 2
everything works as expected. However, if you try to go from 0
to 2
it will essentially noop, terraform believes it is successful and the state is updated. The value for private_ip_count
is not refreshed on terraform refresh
, so then will be forever out of sync with reality. If you then increase the count from your now out of sync 2
to 5
, it will add 3 new IPs.
## Code
```
$ cat main.tf
provider "aws" {
region = "us-west-2"
}
variable "ip_count" {}
resource "aws_network_interface" "foobar" {
subnet_id = "subnet-xxxxxxx"
security_groups = ["sg-xxxxxxx"]
private_ips_count = "${var.ip_count}"
}
output "eni_id" {
value = "${aws_network_interface.foobar.id}"
}
```
## Normal working condition
Start with `private_ips_count=1` and you get what you expect (1 primary ip and 2 secondary ips)
```
$ terraform apply -auto-approve -var ip_count=2
aws_network_interface.foobar: Creating...
attachment.#: "" => "
```
2018/06/01 00:21:26 [INFO] Terraform version: 0.11.7 41e50bd32a8825a84535e353c3674af8ce799161
2018/06/01 00:21:26 [INFO] Go runtime version: go1.10.1
2018/06/01 00:21:26 [INFO] CLI args: []string{"/usr/local/bin/terraform", "apply", "-auto-approve", "-var", "ip_count=2"}
2018/06/01 00:21:26 [DEBUG] Attempting to open CLI config file: /root/.terraformrc
2018/06/01 00:21:26 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2018/06/01 00:21:26 [INFO] CLI command args: []string{"apply", "-auto-approve", "-var", "ip_count=2"}
2018/06/01 00:21:26 [INFO] command: empty terraform config, returning nil
2018/06/01 00:21:26 [DEBUG] command: no data state file found for backend config
2018/06/01 00:21:26 [DEBUG] New state was assigned lineage "8f89cfab-f009-72ea-f99a-489cb0b493ee"
2018/06/01 00:21:26 [INFO] command: backend initialized: ValidationError
2018-06-01T00:21:30.637Z [DEBUG] plugin.terraform-provider-aws_v1.21.0_x4: ValidationError
2018-06-01T00:21:53.688Z [DEBUG] plugin.terraform-provider-aws_v1.21.0_x4: ValidationError
2018-06-01T00:21:55.762Z [DEBUG] plugin.terraform-provider-aws_v1.21.0_x4:
The fix to the aws_network_interface
resource has been merged and will release with version 2.8.0 of the Terraform AWS Provider, shortly.
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!
Terraform Version
Affected Resource(s)
aws_network_interface
Terraform Configuration Files
Expected Behavior
Once the interface has been created, adding/increasing the private_ips_count parameter should cause the provider to allocate additional IP addresses to that ENI.
Actual Behavior
When trying to use the expected new IP (as ${aws_network_interface.privnic.private_ips[2]}) Terraform throws an error:
Steps to Reproduce
The interface was originally created with private_ips_count = 2. This has now been increased to 3 and the new one cannot be used, as per the actual behavior section.