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

failure in zipmap shows doesn't produce warning, just shows empty output #12549

Closed
brikis98 opened this issue Mar 9, 2017 · 6 comments
Closed

Comments

@brikis98
Copy link
Contributor

brikis98 commented Mar 9, 2017

I'm seeing a strange issue where if you create an output variable with a value that uses merge to combine two maps together, if one map is empty, the entire output disappears.

Terraform Version

Terraform v0.8.7

Affected Resource(s)

  • merge function
  • possibly zipmap function

Terraform Configuration Files

The original code is quite complicated and spread across modules. However, I was able to create a convoluted, but standalone repro case:

data "template_file" "foo" {
  count = 5
  template = "foo-${count.index}"
}

data "template_file" "bar" {
  count = 0
  template = "bar-${count.index}"
}

variable "list" {
  type = "list"
  default = [0, 1, 2, 3, 4]
}

variable "empty_list" {
  type = "list"
  default = []
}

output "foo" {
  value = "${zipmap(var.list, data.template_file.foo.*.rendered)}"
}

output "bar" {
  value = "${zipmap(var.empty_list, data.template_file.bar.*.rendered)}"
}

output "foo_bar" {
  value = "${merge(zipmap(var.list, data.template_file.foo.*.rendered), zipmap(var.empty_list, data.template_file.foo.*.rendered))}"
}

Expected Behavior

When I run terraform apply, I expect to see the following outputs:

Outputs:

bar = {}
foo = {
  0 = foo-0
  1 = foo-1
  2 = foo-2
  3 = foo-3
  4 = foo-4
}
foo_bar = {
  0 = foo-0
  1 = foo-1
  2 = foo-2
  3 = foo-3
  4 = foo-4
}

Actual Behavior

I get the outputs above, but without foo_bar:

Outputs:

bar = {}
foo = {
  0 = foo-0
  1 = foo-1
  2 = foo-2
  3 = foo-3
  4 = foo-4
}

It's strange, because zipmap by itself on empty_list and bar returns an empty output, as expected. But merging that exact same (empty) zipmap call with another zipmap call, and the output disappears entirely!

Steps to Reproduce

  1. terraform apply
@jbardin
Copy link
Member

jbardin commented Mar 9, 2017

Hi @brikis98,

Thanks for the full reproduction here.

I think this behavior is a result of outputs not currently displaying error, which I would like to take care of soon.

The zipmap in bar is invalid, because the lists have different length, which fails silently. This doesn't really produce an empty list, though one is displayed.

In the foo_bar case, the failure in zipmap causes the merge function to fail as well, which produces the expected warning in the logs.

I'm going to leave this open for the bar case specifically, because that should not produce output right now, and should produce an error when those get promoted from warnings.

@jbardin jbardin changed the title merge and zipmap cause output to disappear failure in zipmap shows doesn't produce warning, just shows empty output Mar 9, 2017
@brikis98
Copy link
Contributor Author

brikis98 commented Mar 9, 2017

The zipmap in bar is invalid, because the lists have different length, which fails silently. This doesn't really produce an empty list, though one is displayed.

Aren't they both of length 0?

I'm going to leave this open for the bar case specifically, because that should not produce output right now, and should produce an error when those get promoted from warnings.

Empty output seems like the right solution there...

@jbardin
Copy link
Member

jbardin commented Mar 9, 2017

Aren't they both of length 0?

Oh, you're right, they are in the bar case. You have a typo in the foo_bar interpolation, where you're zipmap'ing the empty list with template_file.foo.*. If you fix that the output is correct.

@brikis98
Copy link
Contributor Author

brikis98 commented Mar 9, 2017

Oh, you're right, they are in the bar case. You have a typo in the foo_bar interpolation, where you're zipmap'ing the empty list with template_file.foo.*. If you fix that the output is correct.

Ha, you're right!

That said, this was supposed to be a simple repro of another case where outputs were disappearing. Perhaps I had some typo or error in there too, but Terraform doesn't show an error message in these cases. Is it possible to fix that issue so such bugs are clearer?

@jbardin
Copy link
Member

jbardin commented Mar 9, 2017

yes, missing output is almost always an indication of an error in the output. Currently you need to look at the logs to see the output errors, but we do intend to make these actual errors displayed to the user soon.

I'll close this one as "working as expected" for now

@jbardin jbardin closed this as completed Mar 9, 2017
@ghost
Copy link

ghost commented Apr 15, 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 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants