Is it possible to use the expansion operator when referring to a resource using the splat expression (implying that 0 or more are created)? My initial attempts were unsuccessful at getting this to work.
It would seem possible since References to Named Values mentions the type is a list
:
If the resource has the
count
argument set, the value of this expression is a list of objects representing its instances.
Initial use-case:
variable create {
type = bool
}
resource aws_s3_bucket bucket {
count = var.create ? 1 : 0
...
}
I would expect to be able to use the expansion operator with this, but it doesn’t seem to work. This is a contrived example, but valid:
output bucket_ids {
value = list(aws_s3_bucket.bucket[*].id...)
}
provides the error:
Error: Invalid expanding argument value
on ./outputs.tf line 6, in output "bucket_ids":
6: value = list(aws_s3_bucket.bucket[*].id...)
The expanding argument (indicated by ...) must be of a tuple, list, or set
type.
While there may be better approaches to this case, I think the use of expansion with splat expressions is valid.