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?
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.
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?
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)}"
}
@phinze derp. Great solution!
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. :+1:
wahoo! thanks @phinze!
@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
My bad using the following syntax works (some documentation about this should be nice :))
output "int_subnets" {
value = ["${aws_subnet.int.*.cidr_block}"]
}
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.
Most helpful comment
My bad using the following syntax works (some documentation about this should be nice :))