terraform

Output from module with splat operator not working


I have defined a module with a loop:

module "stamp" {
  for_each = toset(var.stamps)
  source   = "./modules/stamp"
  ...
}

From this I am trying to create an output list, based on this example:

output "stamp_locations" {
  value = module.stamp.*.location
}

However, this validates but on terraform plan I get the error:

│ Error: Unsupported attribute
│ 
│   on output.tf line 3, in output "stamp_locations":
│    3:   value = module.stamp.*.location
│ 
│ This object does not have an attribute named "location"

Only this worked in the end:

output "stamp_locations" {
  value = [for instance in module.stamp : instance.location]
}

So I am wondering: Did I make any mistake or is the splat-syntax not supported with modules and loops?


Solution

  • module.stamp is a map, not a list. The following should work with your map:

    value = values(module.stamp)[*].location 
    

    values will return a list of values from your module.stamp.