From 3607b983e3304cc4e887b4f97272076dd1675c59 Mon Sep 17 00:00:00 2001 From: Fraser Molyneux Date: Fri, 8 Dec 2023 16:35:52 +0000 Subject: [PATCH] Monitoring changes --- terraform/api_management_logger.tf | 8 ++++---- terraform/app_insights.tf | 8 -------- terraform/data.app_insights.tf | 5 +++++ terraform/main.tf | 10 ---------- terraform/tfvars/dev.tfvars | 4 ---- terraform/tfvars/prd.tfvars | 4 ---- terraform/variables.tf | 4 ---- terraform/web_app.tf | 4 ++-- 8 files changed, 11 insertions(+), 36 deletions(-) delete mode 100644 terraform/app_insights.tf create mode 100644 terraform/data.app_insights.tf diff --git a/terraform/api_management_logger.tf b/terraform/api_management_logger.tf index f7cd56d5..e1e9a0fa 100644 --- a/terraform/api_management_logger.tf +++ b/terraform/api_management_logger.tf @@ -1,12 +1,12 @@ resource "azurerm_api_management_named_value" "app_insights_apim_instrumentation_key_named_value" { provider = azurerm.api_management - name = "${azurerm_application_insights.ai.name}-instrumentationkey" + name = "repository${data.azurerm_application_insights.core.name}-instrumentationkey" resource_group_name = data.azurerm_api_management.platform.resource_group_name api_management_name = data.azurerm_api_management.platform.name - display_name = "${azurerm_application_insights.ai.name}-instrumentationkey" + display_name = "repository${data.azurerm_application_insights.core.name}-instrumentationkey" - value = azurerm_application_insights.ai.instrumentation_key + value = data.azurerm_application_insights.core.instrumentation_key depends_on = [ azurerm_role_assignment.apim_kv_role_assignment @@ -20,7 +20,7 @@ resource "azurerm_api_management_logger" "api_management_logger" { api_management_name = data.azurerm_api_management.platform.name resource_group_name = data.azurerm_api_management.platform.resource_group_name - resource_id = azurerm_application_insights.ai.id + resource_id = data.azurerm_application_insights.core.id application_insights { instrumentation_key = "{{${azurerm_api_management_named_value.app_insights_apim_instrumentation_key_named_value.display_name}}}" diff --git a/terraform/app_insights.tf b/terraform/app_insights.tf deleted file mode 100644 index 252092ac..00000000 --- a/terraform/app_insights.tf +++ /dev/null @@ -1,8 +0,0 @@ -resource "azurerm_application_insights" "ai" { - name = local.app_insights_name - location = azurerm_resource_group.rg.location - resource_group_name = azurerm_resource_group.rg.name - workspace_id = "/subscriptions/${var.log_analytics_subscription_id}/resourceGroups/${var.log_analytics_resource_group_name}/providers/Microsoft.OperationalInsights/workspaces/${var.log_analytics_workspace_name}" - - application_type = "web" -} diff --git a/terraform/data.app_insights.tf b/terraform/data.app_insights.tf new file mode 100644 index 00000000..2bfd07c5 --- /dev/null +++ b/terraform/data.app_insights.tf @@ -0,0 +1,5 @@ +//https://github.com/frasermolyneux/portal-core/blob/main/terraform/app_insights.tf +data "azurerm_application_insights" "core" { + name = "ai-portal-core-${var.environment}-${var.location}-${var.instance}" + resource_group_name = "rg-portal-core-${var.environment}-${var.location}-${var.instance}" +} diff --git a/terraform/main.tf b/terraform/main.tf index ab423c21..8f7459c1 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -72,16 +72,6 @@ provider "azurerm" { features {} } -provider "azurerm" { - alias = "log_analytics" - subscription_id = var.log_analytics_subscription_id - - # This is a workload repository so won't have permissions to register providers - skip_provider_registration = true - - features {} -} - data "azurerm_client_config" "current" {} data "azuread_client_config" "current" {} diff --git a/terraform/tfvars/dev.tfvars b/terraform/tfvars/dev.tfvars index 1b946ff4..bb4a441e 100644 --- a/terraform/tfvars/dev.tfvars +++ b/terraform/tfvars/dev.tfvars @@ -24,10 +24,6 @@ dns_subscription_id = "db34f572-8b71-40d6-8f99-f29a27612144" dns_resource_group_name = "rg-platform-dns-prd-uksouth-01" dns_zone_name = "xtremeidiots.dev" -log_analytics_subscription_id = "d68448b0-9947-46d7-8771-baa331a3063a" -log_analytics_resource_group_name = "rg-platform-logging-prd-uksouth-01" -log_analytics_workspace_name = "log-platform-prd-uksouth-01" - tags = { Environment = "dev", Workload = "portal", diff --git a/terraform/tfvars/prd.tfvars b/terraform/tfvars/prd.tfvars index 09c74e07..15dd8e42 100644 --- a/terraform/tfvars/prd.tfvars +++ b/terraform/tfvars/prd.tfvars @@ -24,10 +24,6 @@ dns_subscription_id = "db34f572-8b71-40d6-8f99-f29a27612144" dns_resource_group_name = "rg-platform-dns-prd-uksouth-01" dns_zone_name = "xtremeidiots.dev" -log_analytics_subscription_id = "d68448b0-9947-46d7-8771-baa331a3063a" -log_analytics_resource_group_name = "rg-platform-logging-prd-uksouth-01" -log_analytics_workspace_name = "log-platform-prd-uksouth-01" - tags = { Environment = "prd", Workload = "portal", diff --git a/terraform/variables.tf b/terraform/variables.tf index 72dd3fe7..f8cffc7e 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -32,10 +32,6 @@ variable "dns_subscription_id" {} variable "dns_resource_group_name" {} variable "dns_zone_name" {} -variable "log_analytics_subscription_id" {} -variable "log_analytics_resource_group_name" {} -variable "log_analytics_workspace_name" {} - variable "tags" { default = {} } diff --git a/terraform/web_app.tf b/terraform/web_app.tf index 1b986d80..aa8d97fd 100644 --- a/terraform/web_app.tf +++ b/terraform/web_app.tf @@ -45,8 +45,8 @@ resource "azurerm_linux_web_app" "app" { app_settings = { "minTlsVersion" = "1.2" "READ_ONLY_MODE" = var.environment == "prd" ? "true" : "false" - "APPINSIGHTS_INSTRUMENTATIONKEY" = azurerm_application_insights.ai.instrumentation_key - "APPLICATIONINSIGHTS_CONNECTION_STRING" = azurerm_application_insights.ai.connection_string + "APPINSIGHTS_INSTRUMENTATIONKEY" = data.azurerm_application_insights.core.instrumentation_key + "APPLICATIONINSIGHTS_CONNECTION_STRING" = data.azurerm_application_insights.core.connection_string "ApplicationInsightsAgent_EXTENSION_VERSION" = "~3" "ASPNETCORE_ENVIRONMENT" = var.environment == "prd" ? "Production" : "Development" "WEBSITE_RUN_FROM_PACKAGE" = "1"