Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error: Unsupported attribute when adding outputs

The following code successfully deploys 2 x log analytic workspaces in different regions in azure in their own region based resource groups.

locals.tf

locals {
  resource_groups = {
    for k, v in var.workspaces : k => {
      location = v.location
    }
  }
}

main.tf

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

resource "azurerm_resource_group" "workspaces" {
  for_each = local.resource_groups

  name     = each.key
  location = each.value.location
}

resource "azurerm_log_analytics_workspace" "workspaces" {
  for_each = var.workspaces

  name                = each.key
  location            = each.value.location
  resource_group_name = azurerm_resource_group.workspaces[each.key].name
  sku                 = "PerGB2018"
  retention_in_days   = each.value.retention_in_days
}

variables.tf

variable "workspaces" {
  type = map(object({
    location          = string
    retention_in_days = number
  }))
  default = {
    workspace1 = {
      location          = "australiasoutheast"
      retention_in_days = 30
    }
    workspace2 = {
      location          = "australiaeast"
      retention_in_days = 30
    }
    # Add more workspaces as needed
  }
}

outputs.tf

# Define outputs
output "workspace_ids" {
  value = azurerm_log_analytics_workspace.workspaces[*].id
}

output "workspace_names" {
  value = azurerm_log_analytics_workspace.workspaces[*].name
}

output "resource_group_ids" {
  value = azurerm_resource_group.workspaces[*].id
}

output "resource_group_names" {
  value = azurerm_resource_group.workspaces[*].name
}

output "resource_group_locations" {
  value = azurerm_resource_group.workspaces[*].location
}

When adding outputs I am receiving the following error and im not sure why.

>Solution :

Since you are using for_each, you have to use values. For example:

output "workspace_ids" {
  value = values(azurerm_log_analytics_workspace.workspaces)[*].id
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading