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

enable for_each support for output #23051

Open
chz8494 opened this issue Oct 10, 2019 · 3 comments
Open

enable for_each support for output #23051

chz8494 opened this issue Oct 10, 2019 · 3 comments

Comments

@chz8494
Copy link

chz8494 commented Oct 10, 2019

Current Terraform Version

Terraform version 0.12.10

Use-cases

I've tried newest Terraform and for_each provides an awesome feature that I need, so I'm looking for more from it now.
Let's say I have used for_each during resource definition and created my openstack networks, but I'd like to have output list all new networks IDs.

Attempted Solutions

Tried with for_each or count, none of them seems be allowed to be used in output.

@dan-petty
Copy link
Contributor

I work around this by using for ... in on the same object that created the resources:

output "output_a" {
  value = {
    for key, value in var.object_a :
    key => {
      val_1      = resource_type.resource_a[key].val_1
    }
  }
  description = "Resource A val_1"
}
output "output_b" {
  value = {
    for key, value in var.object_b :
    key => resource_type.resource_b[key]
  }
  description = "Entire Resource B"
}

@iancward
Copy link

iancward commented Feb 6, 2020

I've tried the list comprehension as documented, but that doesn't seem to work, either.

for example, if I have

resource "aws_network_acl_rule" "awedome_rule" {
  for_each [acl1, acl2, acl3]

  network_acl_id = each.value
  ...
}

output "awesome_rule_ids" {
  value = [for acl_rule in aws_network_acl_rule.awesome_rule : acl_rule.id]
}

Output is empty list.
With as much emphasis is put on remote state, it seems like this is a pretty sizable gap with the new for_each feature set.

@iancward
Copy link

iancward commented Feb 7, 2020

The issue I ran into may be particular to the aws_network_acl_rule resource, so I opened hashicorp/terraform-provider-aws#11955

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants