diff --git a/app_services.tf b/app_services.tf index 67fc1b350a..68ff65a12e 100755 --- a/app_services.tf +++ b/app_services.tf @@ -7,7 +7,7 @@ module "app_services" { name = each.value.name resource_group_name = module.resource_groups[each.value.resource_group_key].name location = lookup(each.value, "region", null) == null ? module.resource_groups[each.value.resource_group_key].location : local.global_settings.regions[each.value.region] - app_service_plan_id = lookup(each.value, "app_service_plan_key", null) == null ? null : module.app_service_plans[each.value.app_service_plan_key].id + app_service_plan_id = lookup(each.value, "app_service_plan_key", null) == null ? null : try(module.app_service_plans[each.value.app_service_plan_key].id, data.terraform_remote_state.app_service_remote_plans[each.key].outputs[each.value.remote_tfstate.output_key][each.value.app_service_plan_key].id) settings = each.value.settings identity = try(each.value.identity, {}) connection_strings = try(each.value.connection_strings, {}) @@ -17,6 +17,28 @@ module "app_services" { tags = try(each.value.tags, null) } +# +# Get remote appl service plan to deploy the app service +# +data "terraform_remote_state" "app_service_remote_plans" { + for_each = { + for key, value in local.webapp.app_services : key => value + if try(value.remote_tfstate, null) != null + } + + backend = "azurerm" + config = { + storage_account_name = var.tfstates[each.value.remote_tfstate.tfstate_key].storage_account_name + container_name = var.tfstates[each.value.remote_tfstate.tfstate_key].container_name + resource_group_name = var.tfstates[each.value.remote_tfstate.tfstate_key].resource_group_name + key = var.tfstates[each.value.remote_tfstate.tfstate_key].key + use_msi = var.use_msi + subscription_id = var.use_msi ? var.tfstates[each.value.remote_tfstate.tfstate_key].subscription_id : null + tenant_id = var.use_msi ? var.tfstates[each.value.remote_tfstate.tfstate_key].tenant_id : null + } +} + + output "app_services" { value = module.app_services } diff --git a/modules/webapps/appservice/module.tf b/modules/webapps/appservice/module.tf index 2e68dcbc0a..708e739f30 100755 --- a/modules/webapps/appservice/module.tf +++ b/modules/webapps/appservice/module.tf @@ -24,11 +24,11 @@ resource "azurerm_app_service" "app_service" { https_only = lookup(var.settings, "https_only", null) dynamic "identity" { - for_each = var.identity + for_each = try(var.identity, null) != null ? [1] : [0] content { - type = lookup(var.identity, "type", null) - identity_ids = lookup(var.identity, "identity_ids", null) + type = try(var.identity.type, null) + identity_ids = try(var.identity.identity_ids, null) } } diff --git a/modules/webapps/appservice/slot.tf b/modules/webapps/appservice/slot.tf index 95cc8f632e..250453fd8a 100755 --- a/modules/webapps/appservice/slot.tf +++ b/modules/webapps/appservice/slot.tf @@ -15,11 +15,11 @@ resource "azurerm_app_service_slot" "slots" { https_only = lookup(var.settings, "https_only", null) dynamic "identity" { - for_each = var.identity + for_each = try(var.identity, null) != null ? [1] : [0] content { - type = lookup(var.identity, "type", null) - identity_ids = lookup(var.identity, "identity_ids", null) + type = try(var.identity.type, null) + identity_ids = try(var.identity.identity_ids, null) } }