Skip to content

Commit

Permalink
Deploy appservice to remote appservice plan
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentLesle committed Sep 21, 2020
1 parent 31a62ab commit 9b0ddb5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
24 changes: 23 additions & 1 deletion app_services.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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, {})
Expand All @@ -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
}
6 changes: 3 additions & 3 deletions modules/webapps/appservice/module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
6 changes: 3 additions & 3 deletions modules/webapps/appservice/slot.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 9b0ddb5

Please sign in to comment.