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

Using splats with outputs #2821

Closed
nathanielks opened this issue Jul 22, 2015 · 9 comments
Closed

Using splats with outputs #2821

nathanielks opened this issue Jul 22, 2015 · 9 comments

Comments

@nathanielks
Copy link
Contributor

Good day, all!

I've tried to get the following functionality to work, but I'm not sure terraform has the ability to do this yet. Let's say we have a resource:

resource "aws_subnet" "public" {                                                     
    vpc_id = "${aws_vpc.default.id}"
    cidr_block = "${element(split(",", var.public_subnets), count.index)}"
    availability_zone = "${element(split(",", var.availability_zones), count.index)}"
    count = "${length(split(",", var.public_subnets))}"
}

I know it's possible to reference it in an output like so:

output "public_subnet.0.id" {
    value = "${aws_subnet.public.0.id}"
}

But I'd love to be able to reference all of them automatically:

output "public_subnet.*.id" {
    value = "${aws_subnet.public.*.id}"
}

I couldn't find anything issues/PR's wise. Has this been thought about at all?

@nathanielks
Copy link
Contributor Author

This would also be invaluable with modules that generate an unknown amount of resources, as you have to define the outputs ahead of time. For example, I have a module that generates any number of EC2 instances. Being able to output all their ips would be brilliant so I can reference them in the root module.

@aequitas
Copy link

aequitas commented Oct 6, 2015

I am also running into this issue. I have a module which defines our standard instance layout and want to have an output which lists all instances. But using the splat syntax only gives me one of the two created instances. Have you found a solution in the meantime?

@phinze
Copy link
Contributor

phinze commented Oct 12, 2015

Interesting idea! We'll have to give it some thought.

In the meantime, you can work around this by using join() to output multiple values as a delimited string:

output "public_subnet_ids" {
  value = "${join(",", aws_subnet.public.*.id)}"
}

@nathanielks
Copy link
Contributor Author

@phinze derp. Great solution!

@phinze
Copy link
Contributor

phinze commented Mar 10, 2016

The workaround I submitted is the valid way to do this today - once list support lands in 0.7 this will be a first class feature and not require join(). Going to close this since there's I don't think we need to track it separately from generalized array support. 👍

@phinze phinze closed this as completed Mar 10, 2016
@nathanielks
Copy link
Contributor Author

wahoo! thanks @phinze!

@zfil
Copy link

zfil commented Aug 10, 2016

@phinze this is still broken in 0.7

output "int_subnets" {
  value = "${aws_subnet.int.*.id}"
}

results in
* output 'int_subnets': use of the splat ('*') operator must be wrapped in a list declaration

@zfil
Copy link

zfil commented Aug 10, 2016

My bad using the following syntax works (some documentation about this should be nice :))

output "int_subnets" {
  value = ["${aws_subnet.int.*.cidr_block}"]
}

@ghost
Copy link

ghost commented Apr 23, 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 23, 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

4 participants