Terraform v0.7.0
Assuming a base config as in issue #2821 and this output definition:
output "int_subnets" {
value = ["Subnet with CIDR ${aws_subnet.int.*.cidr_block} is in availability zone ${aws_subnet.int.*.availability_zone}"]
}
I'd expect this to render as:
int_subnets = [
Subnet with CIDR 10.0.0.0/24 is in availability zone eu-west-1a,
Subnet with CIDR 10.0.1.0/24 is in availability zone eu-west-1b
]
(this kind of thing can already be done in an output where splats/lists are not involved)
Nothing is output at all.
Hi @rodom - the formatlist() interpolation function should do what you want here.
An example:
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "int" {
count = 3
vpc_id = "${aws_vpc.main.id}"
cidr_block = "10.0.${count.index}.0/24"
}
output "list" {
value = "${
formatlist(
"Subnet with CIDR %s is in availability zone %s",
aws_subnet.int.*.cidr_block,
aws_subnet.int.*.availability_zone
)}"
}
Outputs:
list = [
Subnet with CIDR 10.0.0.0/24 is in availability zone us-west-2b,
Subnet with CIDR 10.0.1.0/24 is in availability zone us-west-2a,
Subnet with CIDR 10.0.2.0/24 is in availability zone us-west-2a
]
Thanks @phinze that works. It's still not what I'd have expected to be consistent with the non-list case, but it works. As an aside, outputs should not silently fail when there's something wrong with them - is that being addressed?
I'll answer my own question :-) #5334.
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
Hi @rodom - the
formatlist()interpolation function should do what you want here.An example: