Undefined attribute error when referencing module output

Hey there,

I’m having some issues looping over accessing an attribute of one of my modules.

I’ve created a module called oncall which has some outputs defined

output "team_id" {
  value = pagerduty_team.team.id

output "team_name" {
  value = var.team_name

I’m running this module:

module "oncall" {
  for_each  = local.teams
  source    = "./modules/oncall"
  team_name = each.value.name

And I’m trying to reference the output from that instance in another module instance to build a map:

module "users" {
  source = "./modules/users"
  teams  = { for team in module.oncall[*] : team.team_name => team.team_id }

However, when I do so I get an error:

This object does not have an attribute named "team_name".

What should I try here? That error implies to me that the output is not defined, but I can see that it is.


Hi @thebeanogamer,

Applying the [*] operator to the map that represents the instances of module.oncall is turning it into a single-element list with the map as its first element, and so this for expression is traversing that list and visiting the map as a whole rather than the individual elements of the map as I think you intended.

If you remove the [*] then the for expression will traverse the map directly, making team represent each value in the map in turn, which I think is what you were intending here.

1 Like

Hi @apparentlymart,

Yep, that does exactly what I want!

Thanks for the explainer, that’s much more clear now.