I have the following terraform module:
provider "azurerm" {
}
variable "env" {
type = string
description = "The SDLC environment (qa, dev, prod, etc...)"
}
variable "appsvc_names" {
type = list(string)
description = "The names of the app services to create under the same app service plan"
}
locals {
location = "eastus2"
resource_group_name = "app505-dfpg-${var.env}-web-${local.location}"
}
resource "azurerm_app_service_plan" "asp" {
name = "${local.resource_group_name}-asp"
location = local.location
resource_group_name = local.resource_group_name
kind = "Linux"
reserved = true
sku {
tier = "Basic"
size = "B1"
}
}
resource "azurerm_app_service" "appsvc" {
for_each = toset(var.appsvc_names)
name = "${local.resource_group_name}-${each.value}-appsvc"
location = local.location
resource_group_name = local.resource_group_name
app_service_plan_id = azurerm_app_service_plan.asp.id
}
# output "hostnames" {
# value = azurerm_app_service.appsvc[*].default_site_hostname
# description = "The hostnames of the created app services"
# }
It works, but I want to output the hostnames. Preferrably as a map, but for now just a list could be fine too.
When I uncomment the output statement and run terraform apply
I get this:
Error: Unsupported attribute
on ..\..\modules\web\main.tf line 42, in output "hostnames":
42: value = azurerm_app_service.appsvc[*].default_site_hostname
This object does not have an attribute named "default_site_hostname".
So how do I output the list (or better the map) of hostnames of the new app services?
(The question is also posted here - https://stackoverflow.com/questions/59906907/how-to-output-the-hostnames-of-app-services-created-with-for-each-in-terraform)