Created
February 10, 2021 11:52
-
-
Save lawrencegripper/b05872a6d3d72641c7a276c8c1357d53 to your computer and use it in GitHub Desktop.
Enable Diagnostic logs on an Azure storage account with terraform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "random_string" "random" { | |
length = 5 | |
special = false | |
upper = false | |
number = false | |
} | |
resource "azurerm_log_analytics_workspace" "core" { | |
name = "corelaw${random_string.random.result}" | |
location = "westeurope" | |
resource_group_name = "test1" | |
sku = "PerGB2018" | |
retention_in_days = 30 | |
} | |
resource "azurerm_storage_account" "core" { | |
location = "westeurope" | |
resource_group_name = "test1" | |
name = "corestor${random_string.random.result}" | |
account_tier = "Standard" | |
account_replication_type = "LRS" | |
allow_blob_public_access = "false" | |
is_hns_enabled = true | |
enable_https_traffic_only = true | |
} | |
resource "azurerm_monitor_diagnostic_setting" "core-diagnostic" { | |
name = "readwritecore${random_string.random.result}" | |
# See workaround details: https://github.com/terraform-providers/terraform-provider-azurerm/issues/8275#issuecomment-755222989 | |
target_resource_id = "${azurerm_storage_account.core.id}/blobServices/default/" | |
log_analytics_workspace_id = azurerm_log_analytics_workspace.core.id | |
log { | |
category = "StorageRead" | |
enabled = true | |
} | |
log { | |
category = "StorageWrite" | |
enabled = true | |
} | |
metric { | |
category = "Transaction" | |
enabled = true | |
retention_policy { | |
days = 5 | |
enabled = true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment