For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/terraform-azure-postgresql-log-checkpoints-disabled.md. A documentation index is available at /llms.txt.
This product is not supported for your selected Datadog site. ().

Metadata

Id: terraform-azure-postgresql-log-checkpoints-disabled

Provider: Azure

Platform: Terraform

Severity: Medium

Category: Observability

Learn More

Description

The PostgreSQL log_checkpoints parameter controls whether checkpoint activities are logged, which is critical for monitoring and troubleshooting database performance and reliability. If log_checkpoints is set to off, important information about checkpoint events will not be recorded, making it more difficult to detect or respond to potential issues or attacks. To mitigate this risk, the parameter should be enabled, as shown below:

resource "azurerm_postgresql_configuration" "secure_example" {
    name                = "log_checkpoints"
    resource_group_name = data.azurerm_resource_group.example.name
    server_name         = azurerm_postgresql_server.example.name
    value               = "on"
}

Failing to enable this logging may leave administrators unaware of problems that can impact data durability or signal malicious activity, increasing the risk of unnoticed outages or data loss.

Compliant Code Examples

resource "azurerm_resource_group" "example" {
  name     = "test-rg"
  location = "eastus"
}

resource "azurerm_postgresql_server" "example" {
  name                = "psql-server-negative"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  sku_name = "B_Gen5_1"

  storage_mb                   = 5120
  backup_retention_days        = 7
  geo_redundant_backup_enabled = false
  auto_grow_enabled            = true

  administrator_login          = "psqladmin"
  administrator_login_password = "H@Sh1CoR3!"
  version                      = "11"
  ssl_enforcement_enabled      = true
}

resource "azurerm_postgresql_configuration" "negative1" {
  name                = "log_checkpoints"
  resource_group_name = azurerm_resource_group.example.name
  server_name         = azurerm_postgresql_server.example.name
  value               = "on"
}

resource "azurerm_postgresql_configuration" "negative2" {
  name                = "log_checkpoints"
  resource_group_name = azurerm_resource_group.example.name
  server_name         = azurerm_postgresql_server.example.name
  value               = "On"
}

resource "azurerm_postgresql_configuration" "negative3" {
  name                = "log_checkpoints"
  resource_group_name = azurerm_resource_group.example.name
  server_name         = azurerm_postgresql_server.example.name
  value               = "ON"
}

Non-Compliant Code Examples

resource "azurerm_resource_group" "example" {
  name     = "test-rg"
  location = "eastus"
}

resource "azurerm_postgresql_flexible_server" "example" {
  name                   = "psql-positive"
  resource_group_name    = azurerm_resource_group.example.name
  location               = azurerm_resource_group.example.location
  version                = "13"
  administrator_login    = "psqladmin"
  administrator_password = "H@Sh1CoR3!"
  storage_mb             = 32768
  sku_name               = "B_Standard_B1ms"
  zone                   = "1"
}

resource "azurerm_postgresql_flexible_server_configuration" "positive1" {
  name      = "log_checkpoints"
  server_id = azurerm_postgresql_flexible_server.example.id
  value     = "off"
}

resource "azurerm_postgresql_flexible_server_configuration" "positive2" {
  name      = "log_checkpoints"
  server_id = azurerm_postgresql_flexible_server.example.id
  value     = "Off"
}

resource "azurerm_postgresql_flexible_server_configuration" "positive3" {
  name      = "log_checkpoints"
  server_id = azurerm_postgresql_flexible_server.example.id
  value     = "OFF"
}