From 211a9e7875491134084bc51d305c993e2d1d615d Mon Sep 17 00:00:00 2001 From: Rob Gil Date: Wed, 29 Jan 2020 11:34:45 -0500 Subject: [PATCH] Adds log analytics logging to cdn module --- terraform/modules/cdn/main.tf | 12 ++++++++++++ terraform/modules/cdn/variables.tf | 4 ++++ terraform/providers/dev/cdn.tf | 1 + 3 files changed, 17 insertions(+) diff --git a/terraform/modules/cdn/main.tf b/terraform/modules/cdn/main.tf index 5debd443..d6be6a94 100644 --- a/terraform/modules/cdn/main.tf +++ b/terraform/modules/cdn/main.tf @@ -29,3 +29,15 @@ resource "azurerm_cdn_endpoint" "cdn" { host_name = var.origin_host_name } } + +resource "azurerm_monitor_diagnostic_setting" "acr_diagnostic" { + name = "${var.name}-${var.environment}-acr-diag" + target_resource_id = azurerm_cdn_endpoint.cdn.id + log_analytics_workspace_id = var.workspace_id + log { + category = "CoreAnalytics" + retention_policy { + enabled = true + } + } +} diff --git a/terraform/modules/cdn/variables.tf b/terraform/modules/cdn/variables.tf index 3abe4851..ae26c2d2 100644 --- a/terraform/modules/cdn/variables.tf +++ b/terraform/modules/cdn/variables.tf @@ -29,3 +29,7 @@ variable "origin_host_name" { description = "Subdomain to use for the origin in requests to the CDN" } +variable "workspace_id" { + description = "Log Analytics Workspace ID for sending logs generated by this resource" + type = string +} \ No newline at end of file diff --git a/terraform/providers/dev/cdn.tf b/terraform/providers/dev/cdn.tf index 02c17e3d..aa7c5f9a 100644 --- a/terraform/providers/dev/cdn.tf +++ b/terraform/providers/dev/cdn.tf @@ -5,4 +5,5 @@ module "cdn" { environment = var.environment name = var.name region = var.region + workspace_id = module.logs.workspace_id }