Azureサービスのリソースログ収集の確認

重要なAzureサービスで必要なリソースログを収集し、集約先へ送信してください。

説明

リクエストや障害の調査に必要な Azure リソースログを選びます。サブスクリプションのアクティビティ ログには管理操作が記録されます。

想定される影響

リクエストログが欠けると、失敗したリクエストの特定や複数サービスにまたがる調査が難しくなります。

対処方法

既存の収集経路を確認します。必要なログが不足していれば、azurerm_monitor_diagnostic_setting に対象リソースが対応するカテゴリと送信先(Log Analytics、ストレージ、Event Hubs など)を指定します。サービスのログ設定、送信先の権限と保存期間を確認し、実際のリクエストを送ってログを確かめます。

例

例は旧形式の azurerm_app_service を使い、AppServiceHTTPLogs だけをストレージに送ります。利用する AzureRM バージョンに対応した Web アプリ リソースと、必要な追加カテゴリを選びます。

変更前

hcl
resource "azurerm_app_service" "example" {
  name                = "example-app-service"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  app_service_plan_id = azurerm_app_service_plan.example.id
}

変更後

hcl
resource "azurerm_app_service" "example" {
  name                = "example-app-service"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  app_service_plan_id = azurerm_app_service_plan.example.id
}

resource "azurerm_monitor_diagnostic_setting" "example" {
  name               = "app-service-diagnostics"
  target_resource_id = azurerm_app_service.example.id
  storage_account_id = azurerm_storage_account.example.id

  enabled_log {
    category = "AppServiceHTTPLogs"
  }
}

参考資料