diff --git a/.terraform-version b/.terraform-version index 2bf1ca5..ec70f75 100644 --- a/.terraform-version +++ b/.terraform-version @@ -1 +1 @@ -1.1.7 +1.6.6 diff --git a/app-insights.tf b/app-insights.tf index 4c4dc66..a296a1b 100644 --- a/app-insights.tf +++ b/app-insights.tf @@ -1,27 +1,28 @@ resource "azurerm_key_vault_secret" "AZURE_APPINSIGHTS_KEY" { name = "app-insights-instrumentation-key" - value = azurerm_application_insights.appinsights.instrumentation_key + value = module.application_insights.instrumentation_key key_vault_id = module.vault.key_vault_id } resource "azurerm_key_vault_secret" "app_insights_connection_string" { name = "app-insights-connection-string" - value = azurerm_application_insights.appinsights.connection_string + value = module.application_insights.connection_string key_vault_id = module.vault.key_vault_id } -resource "azurerm_application_insights" "appinsights" { - name = "${var.product}-${var.env}" +module "application_insights" { + source = "git@github.com:hmcts/terraform-module-application-insights?ref=main" + + env = var.env + product = var.product location = var.location - resource_group_name = azurerm_resource_group.rg.name application_type = var.application_type - tags = var.common_tags + resource_group_name = azurerm_resource_group.rg.name + + common_tags = var.common_tags +} - lifecycle { - ignore_changes = [ - # Ignore changes to appinsights as otherwise upgrading to the Azure provider 2.x - # destroys and re-creates this appinsights instance - application_type, - ] - } +moved { + from = azurerm_application_insights.appinsights + to = module.application_insights.azurerm_application_insights.this } diff --git a/exception-alert.tf b/exception-alert.tf index 5d880d1..cfd06b0 100644 --- a/exception-alert.tf +++ b/exception-alert.tf @@ -1,8 +1,8 @@ // single alert to minify unnecessary cost because threshold used in here is minimal module "reform-scan-exception-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "Reform_Scan_exception" diff --git a/liveness-alert.tf b/liveness-alert.tf index 4c1fe32..0c3b295 100644 --- a/liveness-alert.tf +++ b/liveness-alert.tf @@ -1,7 +1,7 @@ module "blob-router-service-liveness-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "Blob_Router_Service_liveness" @@ -26,8 +26,8 @@ EOF module "reform-scan-notification-service-liveness-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "Reform_Scan_Notification_Service_liveness" diff --git a/no-envelopes-processed-alert.tf b/no-envelopes-processed-alert.tf index 366eb9f..81a2fa5 100644 --- a/no-envelopes-processed-alert.tf +++ b/no-envelopes-processed-alert.tf @@ -1,7 +1,7 @@ module "no-cft-envelopes-processed-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "No_cft_envelopes_processed_-_Blob_Router" @@ -25,8 +25,8 @@ EOF module "no-crime-envelopes-processed-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "No_crime_envelopes_processed_-_Blob_Router" @@ -50,8 +50,8 @@ EOF module "no-pcq-envelopes-processed-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "No_pcq_envelopes_processed_-_Blob_Router" diff --git a/notification-alert.tf b/notification-alert.tf index b052322..0ed5711 100644 --- a/notification-alert.tf +++ b/notification-alert.tf @@ -1,12 +1,11 @@ module "reform-scan-notifications-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name - - enabled = var.env == "prod" - alert_name = "Reform_Scan_notification" - alert_desc = "Triggers when notification service receives at least 5 notifications within a 30 minutes window timeframe." - common_tags = var.common_tags + location = var.location + app_insights_name = module.application_insights.name + enabled = var.env == "prod" + alert_name = "Reform_Scan_notification" + alert_desc = "Triggers when notification service receives at least 5 notifications within a 30 minutes window timeframe." + common_tags = var.common_tags app_insights_query = "traces | where message startswith 'Started processing notification message'" diff --git a/scheduled-jobs-alert.tf b/scheduled-jobs-alert.tf index d3f5b14..73482fd 100644 --- a/scheduled-jobs-alert.tf +++ b/scheduled-jobs-alert.tf @@ -1,7 +1,7 @@ module "blob-dispatcher-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "Dispatch_Files" @@ -22,8 +22,8 @@ module "blob-dispatcher-alert" { module "delete-dispatched-files-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "Delete_Dispatched_Files" @@ -44,8 +44,8 @@ module "delete-dispatched-files-alert" { module "handle-rejected-files-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "Handle_Rejected_Files" @@ -69,8 +69,8 @@ module "handle-rejected-files-alert" { module "reject-duplicates-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "Reject_Duplicates" @@ -94,8 +94,8 @@ module "reject-duplicates-alert" { module "delete-rejected-files-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "Delete_Rejected_Files" @@ -119,8 +119,8 @@ module "delete-rejected-files-alert" { module "check-new-envelopes-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "Check-New-Envelopes" @@ -142,8 +142,8 @@ module "check-new-envelopes-alert" { module "send-notifications-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "Reform-Scan-Send-Notifications" @@ -164,8 +164,8 @@ module "send-notifications-alert" { module "send-notifications-to-scan-provider-alert" { source = "git@github.com:hmcts/cnp-module-metric-alert" - location = azurerm_application_insights.appinsights.location - app_insights_name = azurerm_application_insights.appinsights.name + location = var.location + app_insights_name = module.application_insights.name enabled = var.env == "prod" alert_name = "Reform-Scan-Pending-Notifications"