I'm creating a list of subnets in my module:
resource "aws_subnet" "public" {
vpc_id = "${var.vpc_id}"
cidr_block = "${element( var.cidrs, count.index)}"
availability_zone = "${element(var.azs, count.index)}"
count = "${length(var.cidrs)}"
tags { Name = "${var.name}.${element(var.azs, count.index)}" }
lifecycle { create_before_destroy = true }
map_public_ip_on_launch = true
}
Setting the output as a list of the created subnet ids:
output "subnet_ids" { value = "${aws_subnet.public.*.id}" }
The error is:
output 'subnet_ids': use of the splat ('*') operator must be wrapped in a list declaration
Workaround:
output "subnet_ids" { value = "${split(",",join(",", aws_subnet.public.*.id))}" }
Terraform v0.7.0-rc2 (46a0709bba004d8b6e0eedad411270b3ae135a9e)
The use of splat should be directly supported without hacking. ( It is already an array.)
I believe the splat operator is not aware of the fact, an output can be an array.
Hi @ocsi01! Thanks for reporting this - it's actually a case of documentation lagging code. I assume from this that you are using a release candidate of Terraform 0.7 or a build from master. The correct output definition here is:
output "subnet_ids" {
value = ["${aws_subnet.public.*.id}"]
}
I do think it might be possible to expand these automatically without the [] wrapper - I'll open a separate issue for that for discussion - it would bring more consistency.
I'll go ahead and close this issue - if the fix proposed doesn't work for you please feel free to re-open!
Hi, I've tried exactly that and doesn't work:
Terraform v0.10.7
output "private_subnets" {
value = ["${aws_subnet.private.*.id}"]
}
$ terraform plan
module 'cluster': aws_subnet.private.*.id is not a valid output for module network
please advise
Resolved with updateding to Terraform v0.10.8
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 @ocsi01! Thanks for reporting this - it's actually a case of documentation lagging code. I assume from this that you are using a release candidate of Terraform 0.7 or a build from master. The correct output definition here is:
I do think it might be possible to expand these automatically without the
[]wrapper - I'll open a separate issue for that for discussion - it would bring more consistency.I'll go ahead and close this issue - if the fix proposed doesn't work for you please feel free to re-open!