Skip to content

Commit

Permalink
Merge pull request #20 from aztfmod/ll-sql-remote-tstate
Browse files Browse the repository at this point in the history
Add rremote state for SQL and app service
  • Loading branch information
arnaudlh authored Sep 21, 2020
2 parents 7c6578c + ede6b0b commit a14e6ab
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 29 deletions.
6 changes: 6 additions & 0 deletions app_service_environments.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ data "terraform_remote_state" "ase_vnets" {
tenant_id = var.use_msi ? var.tfstates[each.value.remote_networking.tfstate_key].tenant_id : null
}
}


output "app_service_environments" {
value = module.app_service_environments
sensitive = true
}
5 changes: 5 additions & 0 deletions app_service_plans.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ module "app_service_plans" {
settings = each.value
global_settings = local.global_settings
}

output app_service_plans {
value = module.app_service_plans
sensitive = true
}
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
}
4 changes: 2 additions & 2 deletions modules/databases/mssql_server/private_endpoints.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ module private_endpoint {
for_each = var.private_endpoints

resource_id = azurerm_mssql_server.mssql.id
name = try(format("%s-to-%s-%s", each.value.name, each.value.vnet_key, each.value.subnet_key), format("%s-to-%s-%s-%s", each.value.name, each.value.remote_tfstate.lz_key, each.value.remote_tfstate.vnet_key, each.value.remote_tfstate.subnet_key))
name = try(format("%s-to-%s-%s", each.value.name, each.value.vnet_key, each.value.subnet_key), format("%s-to-%s-%s-%s", each.value.name, each.value.remote_tfstate.lz_key, each.value.vnet_key, each.value.subnet_key))
location = var.resource_groups[each.value.resource_group_key].location
resource_group_name = var.resource_groups[each.value.resource_group_key].name
subnet_id = try(var.vnets[each.value.vnet_key].subnets[each.value.subnet_key].id, data.terraform_remote_state.vnets[each.key].outputs[each.value.remote_tfstate.output_key][each.value.remote_tfstate.lz_key][each.value.remote_tfstate.vnet_key].subnets[each.value.remote_tfstate.subnet_key].id)
subnet_id = try(var.vnets[each.value.vnet_key].subnets[each.value.subnet_key].id, data.terraform_remote_state.vnets[each.key].outputs[each.value.remote_tfstate.output_key][each.value.remote_tfstate.lz_key][each.value.vnet_key].subnets[each.value.subnet_key].id)
settings = each.value
global_settings = var.global_settings
}
Expand Down
9 changes: 5 additions & 4 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 Expand Up @@ -270,4 +270,5 @@ resource "azurerm_template_deployment" "site_config" {
}

deployment_mode = "Incremental"
}
}

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
20 changes: 10 additions & 10 deletions modules/webapps/appservice/variables.tf
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@


variable "tags" {
variable tags {
description = "(Required) map of tags for the deployment"
}

variable "name" {
variable name {
description = "(Required) Name of the App Service"
}

variable "location" {
variable location {
description = "(Required) Resource Location"
}

variable "resource_group_name" {
variable resource_group_name {
description = "(Required) Resource group of the App Service"
}

variable "app_service_plan_id" {
variable app_service_plan_id {
}

variable "identity" {
variable identity {
default = {}
}

variable "connection_strings" {
variable connection_strings {
default = {}
}

variable "app_settings" {
variable app_settings {
default = null
}

variable "slots" {
variable slots {
default = {}
}

variable "settings" {}
variable settings {}

variable global_settings {}
18 changes: 15 additions & 3 deletions modules/webapps/ase/output.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
output "id" {
output id {
value = lookup(azurerm_template_deployment.ase.outputs, "id")
description = "App Service Environment Resource Id"
}

output "name" {
output name {
value = azurecaf_name.ase.result
description = "App Service Environment Name"
}

output "ilb_ip" {
output ilb_ip {
value = data.external.ase_ilb_ip.result.internalIpAddress
}

output subnet_id {
value = var.subnet_id
}

output zone {
value = var.zone
}

output a_records {
value = azurerm_private_dns_a_record.a_records
}
10 changes: 6 additions & 4 deletions modules/webapps/asp/output.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
output "id" {
output id {
value = azurerm_app_service_plan.asp.id
sensitive = true
}

output "maximum_number_of_workers" {
output maximum_number_of_workers {
value = azurerm_app_service_plan.asp.maximum_number_of_workers
sensitive = true
}

output ase_id {
value = var.app_service_environment_id
}
4 changes: 2 additions & 2 deletions solutions/examples/mssql_server/200-mssql-two-regions.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ mssql_servers = {
tfstate_key = "foundations"
lz_key = "launchpad"
output_key = "vnets"
vnet_key = "devops_region1"
subnet_key = "private_endpoints"
}
vnet_key = "devops_region1"
subnet_key = "private_endpoints"
resource_group_key = "sql_region1"

private_service_connection = {
Expand Down

0 comments on commit a14e6ab

Please sign in to comment.