How to work with azurerm_monitor_diagnostic_settings

275 views
Skip to first unread message

Sawyer Hollenshead

unread,
May 31, 2019, 6:01:43 PM5/31/19
to Terraform
Hi, I'm struggling to wrap my head around the expected usage of azurerm_monitor_diagnostic_settings, specifically the "logs" and "metrics" arguments. 

Question 1: Is it expected that you define settings for each log and metric category that a resource accepts, or are you able to just define the category that you want to enable? It appears on subsequent "terraform apply" runs that terraform shows a diff indicating changes to the categories that weren't defined in the config block. For example, with the following config block:

resource "azurerm_monitor_diagnostic_setting" "db" {
  name               = "db-audit-records"
  target_resource_id = "${azurerm_cosmosdb_account.db.id}"
  storage_account_id = "${azurerm_storage_account.audit_records.id}"

  log {
    category = "DataPlaneRequests"
    enabled  = true

    retention_policy {
      enabled = false
    }
  }
}

on a subsequent "terraform apply," I receive the following:

Terraform will perform the following actions:

  ~ module.instance.azurerm_monitor_diagnostic_setting.db
      log.#:                                        "3" => "1"
      log.2322944631.category:                      "DataPlaneRequests" => "DataPlaneRequests"
      log.2322944631.enabled:                       "true" => "true"
      log.2322944631.retention_policy.#:            "1" => "1"
      log.2322944631.retention_policy.0.days:       "0" => "0"
      log.2322944631.retention_policy.0.enabled:    "false" => "false"
      log.235918854.category:                       "QueryRuntimeStatistics" => ""
      log.235918854.enabled:                        "false" => "false"
      log.235918854.retention_policy.#:             "1" => "0"
      log.235918854.retention_policy.0.days:        "0" => "0"
      log.235918854.retention_policy.0.enabled:     "false" => "false"
      log.3876472479.category:                      "MongoRequests" => ""
      log.3876472479.enabled:                       "false" => "false"
      log.3876472479.retention_policy.#:            "1" => "0"
      log.3876472479.retention_policy.0.days:       "0" => "0"
      log.3876472479.retention_policy.0.enabled:    "false" => "false"
      metric.#:                                     "1" => "0"
      metric.1222937415.category:                   "Requests" => ""
      metric.1222937415.enabled:                    "false" => "false"
      metric.1222937415.retention_policy.#:         "1" => "0"
      metric.1222937415.retention_policy.0.days:    "0" => "0"
      metric.1222937415.retention_policy.0.enabled: "false" => "false"

Question 2: Another point of confusion for me, as a newcomer to Terraform, is if and how I should be using azurerm_monitor_diagnostic_categories in combination with azurerm_monitor_diagnostic_settings. Are there any examples of this that I could reference? The docs are pretty vague when it comes to this area.
Reply all
Reply to author
Forward
0 new messages