Description
When Azure SQL audit logs go to Blob Storage, set the required period on the applicable server or database audit policy. retention_in_days = 0 sets no expiry under that policy.
Potential impact
Increasing retention cannot recover access or change records that have already been deleted.
Remediation
Compare retention_in_days with the storage account’s deletion rules. Check both an older record from the period you need and a recent audited event to verify retention and delivery.
Examples
The examples increase retention on a separate server audit policy from 20 days to 95. Choose the period your organization needs and manage production credentials separately.
Before
hcl
resource "azurerm_mssql_server" "example" {
name = "mssqlserver"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
version = "12.0"
administrator_login = "mradministrator"
administrator_login_password = "thisIsDog11"
}
resource "azurerm_mssql_server_extended_auditing_policy" "example" {
server_id = azurerm_mssql_server.example.id
blob_storage_endpoint = azurerm_storage_account.example.primary_blob_endpoint
storage_account_access_key = azurerm_storage_account.example.primary_access_key
storage_account_access_key_is_secondary = false
retention_in_days = 20
}
After
hcl
resource "azurerm_mssql_server" "example" {
name = "mssqlserver"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
version = "12.0"
administrator_login = "mradministrator"
administrator_login_password = "thisIsDog11"
}
resource "azurerm_mssql_server_extended_auditing_policy" "example" {
server_id = azurerm_mssql_server.example.id
blob_storage_endpoint = azurerm_storage_account.example.primary_blob_endpoint
storage_account_access_key = azurerm_storage_account.example.primary_access_key
storage_account_access_key_is_secondary = false
retention_in_days = 95
}