From 98405cf97ac10ecbb6e8c474456a20adae66bf1d Mon Sep 17 00:00:00 2001 From: nileshgadgi Date: Fri, 7 Apr 2023 19:58:16 +0530 Subject: [PATCH 1/2] [Hurodata-51] add - existing app insights service can be attached to app service --- _example/complete/main.tf | 6 +++--- main.tf | 43 ++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/_example/complete/main.tf b/_example/complete/main.tf index 45bb372..ba7b11d 100644 --- a/_example/complete/main.tf +++ b/_example/complete/main.tf @@ -8,8 +8,8 @@ module "resource_group" { version = "1.0.1" label_order = ["name", "environment"] - name = "rg-rbac" - environment = "examplee" + name = "rg-example" + environment = "test" location = "Canada Central" } @@ -18,7 +18,7 @@ module "app-service" { source = "../../" enabled = true name = "app" - environment = "test" + environment = "teting" label_order = ["name", "environment", ] resource_group_name = module.resource_group.resource_group_name location = module.resource_group.resource_group_location diff --git a/main.tf b/main.tf index a1edb7e..043ae1d 100644 --- a/main.tf +++ b/main.tf @@ -20,29 +20,36 @@ locals { # app insights app_insights = try(data.azurerm_application_insights.main.0, try(azurerm_application_insights.main.0, {})) + default_app_settings = var.application_insights_enabled ? { + APPLICATION_INSIGHTS_IKEY = try(local.app_insights.instrumentation_key, "") + APPINSIGHTS_INSTRUMENTATIONKEY = try(local.app_insights.instrumentation_key, "") + APPLICATIONINSIGHTS_CONNECTION_STRING = try(local.app_insights.connection_string, "") + ApplicationInsightsAgent_EXTENSION_VERSION = "~2" + } : {} + # Default configuration for Site config block default_site_config = { always_on = "true" } ip_address = [for ip_address in var.ips_allowed : { - name = "ip_restriction_cidr_${join("", [1, index(var.ips_allowed, ip_address)])}" - ip_address = ip_address - virtual_network_subnet_id = null - service_tag = null - subnet_id = null - priority = join("", [1, index(var.ips_allowed, ip_address)]) - action = "Allow" + name = "ip_restriction_cidr_${join("", [1, index(var.ips_allowed, ip_address)])}" + ip_address = ip_address + virtual_network_subnet_id = null + service_tag = null + subnet_id = null + priority = join("", [1, index(var.ips_allowed, ip_address)]) + action = "Allow" }] subnets = [for subnet in var.subnet_ids_allowed : { - name = "ip_restriction_subnet_${join("", [1, index(var.subnet_ids_allowed, subnet)])}" - ip_address = null - virtual_network_subnet_id = subnet - service_tag = null - subnet_id = subnet - priority = join("", [1, index(var.subnet_ids_allowed, subnet)]) - action = "Allow" + name = "ip_restriction_subnet_${join("", [1, index(var.subnet_ids_allowed, subnet)])}" + ip_address = null + virtual_network_subnet_id = subnet + service_tag = null + subnet_id = subnet + priority = join("", [1, index(var.subnet_ids_allowed, subnet)]) + action = "Allow" }] } @@ -79,7 +86,7 @@ resource "azurerm_app_service" "main" { https_only = var.enable_https client_cert_enabled = var.enable_client_certificate tags = module.labels.tags - app_settings = var.app_settings + app_settings = merge(local.default_app_settings, var.app_settings) dynamic "site_config" { for_each = [merge(local.default_site_config, var.site_config)] @@ -222,18 +229,12 @@ resource "azurerm_private_dns_zone_virtual_network_link" "vent-link" { # App Insights data "azurerm_application_insights" "main" { - depends_on = [ - azurerm_app_service.main - ] count = var.application_insights_enabled && var.application_insights_id != null ? 1 : 0 name = split("/", var.application_insights_id)[8] resource_group_name = split("/", var.application_insights_id)[4] } resource "azurerm_application_insights" "main" { - depends_on = [ - azurerm_app_service.main - ] count = var.application_insights_enabled && var.application_insights_id == null ? 1 : 0 name = lower(format("app-insights-%s", var.app_insights_name)) location = var.location From 81c0b432078aa3f9e9366487487329f2c053df8a Mon Sep 17 00:00:00 2001 From: nileshgadgi Date: Fri, 7 Apr 2023 20:02:55 +0530 Subject: [PATCH 2/2] [Hurodata-51] fix - ran terraform fmt command --- main.tf | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/main.tf b/main.tf index 043ae1d..ab16b76 100644 --- a/main.tf +++ b/main.tf @@ -33,23 +33,23 @@ locals { } ip_address = [for ip_address in var.ips_allowed : { - name = "ip_restriction_cidr_${join("", [1, index(var.ips_allowed, ip_address)])}" - ip_address = ip_address - virtual_network_subnet_id = null - service_tag = null - subnet_id = null - priority = join("", [1, index(var.ips_allowed, ip_address)]) - action = "Allow" + name = "ip_restriction_cidr_${join("", [1, index(var.ips_allowed, ip_address)])}" + ip_address = ip_address + virtual_network_subnet_id = null + service_tag = null + subnet_id = null + priority = join("", [1, index(var.ips_allowed, ip_address)]) + action = "Allow" }] subnets = [for subnet in var.subnet_ids_allowed : { - name = "ip_restriction_subnet_${join("", [1, index(var.subnet_ids_allowed, subnet)])}" - ip_address = null - virtual_network_subnet_id = subnet - service_tag = null - subnet_id = subnet - priority = join("", [1, index(var.subnet_ids_allowed, subnet)]) - action = "Allow" + name = "ip_restriction_subnet_${join("", [1, index(var.subnet_ids_allowed, subnet)])}" + ip_address = null + virtual_network_subnet_id = subnet + service_tag = null + subnet_id = subnet + priority = join("", [1, index(var.subnet_ids_allowed, subnet)]) + action = "Allow" }] }