retention_policy
has been deprecated in favor of azurerm_storage_management_policy
resource – to learn more https://aka.ms/diagnostic_settings_log_retention
do you know and have some examples how to implement it using the azurerm_storage_management_policy resource?
so how to implement this block using:
resource "azurerm_monitor_diagnostic_setting" "example" {
log_analytics_workspace_id = var.log_analytics_workspace_id
name = "example"
target_resource_id = azurerm_linux_web_app.example.id
log {
category = "AppServiceHTTPLogs"
enabled = true
retention_policy {
enabled = true
days = 10
}
}
did not try with azure azurerm_storage_management_policy
since from documentation it is not clear how to do it?
2
Answers
First, set up azurerm_monitor_diagnostic_setting without retention_policy:
Then, define the retention using azurerm_storage_management_policy:
The
retention_policy
block inside theazurerm_monitor_diagnostic_setting
resource is no longer supported. You need to use theazurerm_storage_management_policy
resource to manage how long logs are kept in Azure.You can use
azurerm_storage_management_policy
to set up log retention. First, create a storage account where you will store the logs as blobs. Then, define a storage management policy for the blobs and specify the retention period for the logs.My terraform configuration:
Output: