TerraformでAzure Managed Redisの監査ログを出力

事象

  • Azureのキャッシュの実現方法として、Azure Cache for Redisが使用されてきましたが、2025年5月にAzure Managed Redisが一般公開(GA)され、こちらが推奨されるようになりました。
  • Azure Managed Redisで監査ログを取得する場合、診断設定にてカテゴリーグループauditを選択します。
  • Terraformで次のコードのようにカテゴリーグループを指定すると、サポートされていない旨のエラーになります。
    resource "azurerm_resource_group" "example" {
      name     = "test-tmp"
      location = "japaneast"
    }
    
    resource "azurerm_managed_redis" "example" {
      name                      = "redis-example"
      resource_group_name       = azurerm_resource_group.example.name
      location                  = azurerm_resource_group.example.location
      sku_name                  = "Balanced_B0"
      high_availability_enabled = false
      public_network_access     = "Enabled"
    
      default_database {} # データベースの作成に必要
    }
    
    resource "azurerm_storage_account" "example" {
      name                     = "stexample123456789"
      resource_group_name      = azurerm_resource_group.example.name
      location                 = azurerm_resource_group.example.location
      account_tier             = "Standard"
      account_replication_type = "LRS"
    }
    
    resource "azurerm_monitor_diagnostic_setting" "this" {
      name               = "test-diag-redis"
      target_resource_id = azurerm_managed_redis.example.id
      storage_account_id = azurerm_storage_account.example.id
    
      enabled_log {
        category_group = "audit"
      }
    }
  • 具体的なエラーの内容は次の通りです。
    │ Error: creating Monitor Diagnostics Setting "xxx-diag-redis" for Resource
    "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Cache/redisEnterprise/redis-example":
    unexpected status 400 (400 Bad Request) with response: 
    {"code":"BadRequest","message":"CategoryGroup: 'audit' is not supported, supported ones are: ''"}

対応

  • 診断設定の対象としてAzure Managed RedisのIDを指定していますが、このIDに対象データベースを含めることで解決できます。
    (2026年2月現在、情報が乏しく、AIからの情報もあやふやで、対応方法を調べるのに苦労しました。)

    resource "azurerm_monitor_diagnostic_setting" "this" {
      name               = "test-diag-redis"
      target_resource_id = "${azurerm_managed_redis.example.id}/databases/default"
      storage_account_id = azurerm_storage_account.example.id
    
      enabled_log {
        category_group = "audit"
      }
    }
  • 参考