From acab31f4a9ccac3320391d44b8124b7ad41c56b9 Mon Sep 17 00:00:00 2001 From: Teresa Crane Date: Mon, 27 Nov 2023 10:06:10 -0500 Subject: [PATCH] Add log analytics and update app insights --- infrastructure/bicep/main.bicep | 12 ++++++++ .../bicep/modules/application_insights.bicep | 2 ++ .../modules/log_analytics_workspace.bicep | 16 ++++++++++ infrastructure/terraform/aml_deploy.tf | 15 ++++++++++ .../modules/application-insights/main.tf | 3 +- .../modules/application-insights/variables.tf | 7 ++++- .../modules/log-analytics-workspace/main.tf | 8 +++++ .../log-analytics-workspace/outputs.tf | 3 ++ .../log-analytics-workspace/variables.tf | 30 +++++++++++++++++++ 9 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 infrastructure/bicep/modules/log_analytics_workspace.bicep create mode 100644 infrastructure/terraform/modules/log-analytics-workspace/main.tf create mode 100644 infrastructure/terraform/modules/log-analytics-workspace/outputs.tf create mode 100644 infrastructure/terraform/modules/log-analytics-workspace/variables.tf diff --git a/infrastructure/bicep/main.bicep b/infrastructure/bicep/main.bicep index 612759b..c06e172 100644 --- a/infrastructure/bicep/main.bicep +++ b/infrastructure/bicep/main.bicep @@ -45,6 +45,17 @@ module kv './modules/key_vault.bicep' = { } } +// Log Analytics Workspace +module log './modules/log_analytics_workspace.bicep' = { + name: 'log' + scope: resourceGroup(rg.name) + params: { + baseName: baseName + location: location + tags: tags + } +} + // App Insights module appi './modules/application_insights.bicep' = { name: 'appi' @@ -52,6 +63,7 @@ module appi './modules/application_insights.bicep' = { params: { baseName: baseName location: location + workspaceResourceId: log.outputs.logOut tags: tags } } diff --git a/infrastructure/bicep/modules/application_insights.bicep b/infrastructure/bicep/modules/application_insights.bicep index aab35cd..1e2354e 100644 --- a/infrastructure/bicep/modules/application_insights.bicep +++ b/infrastructure/bicep/modules/application_insights.bicep @@ -1,5 +1,6 @@ param baseName string param location string +param workspaceResourceId string param tags object // App Insights @@ -9,6 +10,7 @@ resource appinsight 'Microsoft.Insights/components@2020-02-02-preview' = { kind: 'web' properties: { Application_Type: 'web' + WorkspaceResourceId: workspaceResourceId } tags: tags diff --git a/infrastructure/bicep/modules/log_analytics_workspace.bicep b/infrastructure/bicep/modules/log_analytics_workspace.bicep new file mode 100644 index 0000000..71ea06a --- /dev/null +++ b/infrastructure/bicep/modules/log_analytics_workspace.bicep @@ -0,0 +1,16 @@ +param baseName string +param location string +param tags object + +resource log 'Microsoft.OperationalInsights/workspaces@2022-10-01' = { + name: 'log-${baseName}' + location: location + properties: { + sku: { + name: 'PerGB2018' + } + } + tags: tags +} + +output logOut string = log.id diff --git a/infrastructure/terraform/aml_deploy.tf b/infrastructure/terraform/aml_deploy.tf index 9804572..6c0f89b 100644 --- a/infrastructure/terraform/aml_deploy.tf +++ b/infrastructure/terraform/aml_deploy.tf @@ -69,6 +69,19 @@ module "key_vault" { tags = local.tags } +module "log_analytics_workspace" { + source = "./modules/log-analytics-workspace" + + rg_name = module.resource_group.name + location = module.resource_group.location + + prefix = var.prefix + postfix = var.postfix + env = var.environment + + tags = local.tags +} + # Application insights module "application_insights" { @@ -81,6 +94,8 @@ module "application_insights" { postfix = var.postfix env = var.environment + log_analytics_workspace_id = module.log_analytics_workspace.id + tags = local.tags } diff --git a/infrastructure/terraform/modules/application-insights/main.tf b/infrastructure/terraform/modules/application-insights/main.tf index ba11fe7..10111c9 100644 --- a/infrastructure/terraform/modules/application-insights/main.tf +++ b/infrastructure/terraform/modules/application-insights/main.tf @@ -3,6 +3,7 @@ resource "azurerm_application_insights" "appi" { location = var.location resource_group_name = var.rg_name application_type = "web" + workspace_id = var.log_analytics_workspace_id tags = var.tags -} \ No newline at end of file +} diff --git a/infrastructure/terraform/modules/application-insights/variables.tf b/infrastructure/terraform/modules/application-insights/variables.tf index 3c3f8d2..d912986 100644 --- a/infrastructure/terraform/modules/application-insights/variables.tf +++ b/infrastructure/terraform/modules/application-insights/variables.tf @@ -27,4 +27,9 @@ variable "postfix" { variable "env" { type = string description = "Environment prefix" -} \ No newline at end of file +} + +variable "log_analytics_workspace_id" { + type = string + description = "Log Analytics Workspace Id" +} diff --git a/infrastructure/terraform/modules/log-analytics-workspace/main.tf b/infrastructure/terraform/modules/log-analytics-workspace/main.tf new file mode 100644 index 0000000..fbbe5ba --- /dev/null +++ b/infrastructure/terraform/modules/log-analytics-workspace/main.tf @@ -0,0 +1,8 @@ +resource "azurerm_log_analytics_workspace" "log" { + name = "log-${var.prefix}-${var.postfix}${var.env}" + location = var.location + resource_group_name = var.rg_name + sku = "PerGB2018" + + tags = var.tags +} diff --git a/infrastructure/terraform/modules/log-analytics-workspace/outputs.tf b/infrastructure/terraform/modules/log-analytics-workspace/outputs.tf new file mode 100644 index 0000000..256f70c --- /dev/null +++ b/infrastructure/terraform/modules/log-analytics-workspace/outputs.tf @@ -0,0 +1,3 @@ +output "id" { + value = azurerm_log_analytics_workspace.log.id +} diff --git a/infrastructure/terraform/modules/log-analytics-workspace/variables.tf b/infrastructure/terraform/modules/log-analytics-workspace/variables.tf new file mode 100644 index 0000000..786c7fc --- /dev/null +++ b/infrastructure/terraform/modules/log-analytics-workspace/variables.tf @@ -0,0 +1,30 @@ +variable "rg_name" { + type = string + description = "Resource group name" +} + +variable "location" { + type = string + description = "Location of the resource group" +} + +variable "tags" { + type = map(string) + default = {} + description = "A mapping of tags which should be assigned to the deployed resource" +} + +variable "prefix" { + type = string + description = "Prefix for the module name" +} + +variable "postfix" { + type = string + description = "Postfix for the module name" +} + +variable "env" { + type = string + description = "Environment prefix" +}