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 empty string in 0.8.2 #10908

Closed
eric-johnson opened this issue Dec 22, 2016 · 6 comments · Fixed by #11042
Closed

aws_network_interface.private_ips empty string in 0.8.2 #10908

eric-johnson opened this issue Dec 22, 2016 · 6 comments · Fixed by #11042

Comments

@eric-johnson
Copy link

Hi there,

I upgraded to 0.8.2 and am having issues getting ip addresses off of aws_network_interfaces.

Terraform Version

0.8.2 (does not happen in 0.8.1)

Affected Resource(s)

  • aws_network_interface

Terraform Configuration Files

The full config is here: https://gist.github.com/eric-johnson/e73255b833844fbb1e010daf1b5c107b

...

resource "aws_network_interface" "test" {
  subnet_id = "${element(split(",", module.vpc.external_subnets), 0)}"
  subnet_id = "${aws_subnet.external.id}"
  security_groups = ["${aws_security_group.sg.id}"]
  tags { Name = "test-8.2" }
}

resource "null_resource" "test" {
  triggers {
    id = "${aws_network_interface.test.subnet_id}"
  }

  provisioner "local-exec" {
    command = "echo ${join("-", aws_network_interface.test.private_ips)} ${jsonencode(aws_network_interface.test.private_ips)}"
  }
}

Output

https://gist.github.com/eric-johnson/e73255b833844fbb1e010daf1b5c107b
I have a debug log, but I'd rather not have to strip out sensitive info from it.

Expected Behavior

The local-exec provisioner should be printing out the private_ips of the network_interface.
This line should have the private ip address in it.

Actual Behavior

The network interface's private_ips was a list with an empty string.

Steps to Reproduce

  1. terraform apply

Important Factoids

This does not occur in terraform 0.8.1

@2rs2ts
Copy link
Contributor

2rs2ts commented Dec 23, 2016

This broke a workaround I was using to get around another issue about list flattening. 😞

Through bisecting, I was able to determine that this was caused by #10787 cc @jbardin. I'll try to see if I can fix it, but I'm not really familiar with the codebase and barely know Go, so I wouldn't get my hopes up if I were you.

2rs2ts added a commit to 2rs2ts/terraform that referenced this issue Dec 23, 2016
The change in hashicorp#10787 used flatmap.Expand to fix interpolation of nested
maps, but it broke interpolation of Sets such that their elements were
not represented. For example, the expected string representation of a
splatted aws_network_interface.whatever.*.private_ips should be:

```
[{Variable (TypeList): [{Variable (TypeString): 10.41.17.25}]} {Variable (TypeList): [{Variable (TypeString): 10.41.22.236}]}]
```

But instead it became:

```
[{Variable (TypeList): [{Variable (TypeString): }]} {Variable (TypeList): [{Variable (TypeString): }]}]
```

This is because the expandArray function of expand.go treated arrays to
exclusively be lists, e.g. not sets. The old code used to match for
numeric keys, so it would work for sets, whereas expandArray just
assumed keys started at 0 and ascended incrementally. Remember that
sets' keys are numeric, but since they are hashes, they can be any
integer. The result of assuming that the keys start at 0 led to the
recursive call to flatmap.Expand not matching any keys of the set, and
returning nil, which is why the above example has nothing where the IP
addresses used to be.

So we bring back that matching behavior, but we move it to expandArray
instead. We've modified it to not reconstruct the data structures like
it used to when it was in the Interpolator, and to use the standard int
sorter rather than implementing a custom sorter since a custom one is no
longer necessary thanks to the use of flatmap.Expand.

Fixes hashicorp#10908, and restores the viability of the workaround I posted in hashicorp#8696.

Big thanks to @jszwedko for helping me with this fix. I was able to
diagnose the problem along, but couldn't fix it without his help.

Signed-off-by: Jesse Szwedko <jesse.szwedko@getbraintree.com>
2rs2ts added a commit to 2rs2ts/terraform that referenced this issue Dec 23, 2016
The change in hashicorp#10787 used flatmap.Expand to fix interpolation of nested
maps, but it broke interpolation of Sets such that their elements were
not represented. For example, the expected string representation of a
splatted aws_network_interface.whatever.*.private_ips should be:

```
[{Variable (TypeList): [{Variable (TypeString): 10.41.17.25}]} {Variable (TypeList): [{Variable (TypeString): 10.41.22.236}]}]
```

But instead it became:

```
[{Variable (TypeList): [{Variable (TypeString): }]} {Variable (TypeList): [{Variable (TypeString): }]}]
```

This is because the expandArray function of expand.go treated arrays to
exclusively be lists, e.g. not sets. The old code used to match for
numeric keys, so it would work for sets, whereas expandArray just
assumed keys started at 0 and ascended incrementally. Remember that
sets' keys are numeric, but since they are hashes, they can be any
integer. The result of assuming that the keys start at 0 led to the
recursive call to flatmap.Expand not matching any keys of the set, and
returning nil, which is why the above example has nothing where the IP
addresses used to be.

So we bring back that matching behavior, but we move it to expandArray
instead. We've modified it to not reconstruct the data structures like
it used to when it was in the Interpolator, and to use the standard int
sorter rather than implementing a custom sorter since a custom one is no
longer necessary thanks to the use of flatmap.Expand.

Fixes hashicorp#10908, and restores the viability of the workaround I posted in hashicorp#8696.

Big thanks to @jszwedko for helping me with this fix. I was able to
diagnose the problem along, but couldn't fix it without his help.
2rs2ts added a commit to 2rs2ts/terraform that referenced this issue Dec 23, 2016
The change in hashicorp#10787 used flatmap.Expand to fix interpolation of nested
maps, but it broke interpolation of sets such that their elements were
not represented. For example, the expected string representation of a
splatted aws_network_interface.whatever.*.private_ips should be:

```
[{Variable (TypeList): [{Variable (TypeString): 10.41.17.25}]} {Variable (TypeList): [{Variable (TypeString): 10.41.22.236}]}]
```

But instead it became:

```
[{Variable (TypeList): [{Variable (TypeString): }]} {Variable (TypeList): [{Variable (TypeString): }]}]
```

This is because the expandArray function of expand.go treated arrays to
exclusively be lists, e.g. not sets. The old code used to match for
numeric keys, so it would work for sets, whereas expandArray just
assumed keys started at 0 and ascended incrementally. Remember that
sets' keys are numeric, but since they are hashes, they can be any
integer. The result of assuming that the keys start at 0 led to the
recursive call to flatmap.Expand not matching any keys of the set, and
returning nil, which is why the above example has nothing where the IP
addresses used to be.

So we bring back that matching behavior, but we move it to expandArray
instead. We've modified it to not reconstruct the data structures like
it used to when it was in the Interpolator, and to use the standard int
sorter rather than implementing a custom sorter since a custom one is no
longer necessary thanks to the use of flatmap.Expand.

Fixes hashicorp#10908, and restores the viability of the workaround I posted in hashicorp#8696.

Big thanks to @jszwedko for helping me with this fix. I was able to
diagnose the problem along, but couldn't fix it without his help.
@2rs2ts
Copy link
Contributor

2rs2ts commented Dec 23, 2016

Thanks to some help from a colleague, I was able to submit a fix. 🤞

@stack72 stack72 added core and removed provider/aws labels Jan 4, 2017
@stack72
Copy link
Contributor

stack72 commented Jan 4, 2017

Related to #10926

@mcraig88
Copy link

This reproduces in v0.8.7.

  • resource 'null_resource.test' config: use of the splat ('*') operator must be wrapped in a list declaration
    module vpc.us-west-2.root: 1 error(s) occurred:

  • resource 'null_resource.test' config: use of the splat ('*') operator must be wrapped in a list declaration

@aaomoware
Copy link

Terraform v0.8.6

same ish.
"dns_ip_addresses.#": "0",

@ghost
Copy link

ghost commented Apr 16, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants