diff --git a/azurerm/resource_arm_monitor_diagnostic_setting.go b/azurerm/resource_arm_monitor_diagnostic_setting.go index ba1a98812452..fb44b65d9128 100644 --- a/azurerm/resource_arm_monitor_diagnostic_setting.go +++ b/azurerm/resource_arm_monitor_diagnostic_setting.go @@ -73,6 +73,13 @@ func resourceArmMonitorDiagnosticSetting() *schema.Resource { ValidateFunc: azure.ValidateResourceID, }, + "log_analytics_destination_type": { + Type: schema.TypeString, + Optional: true, + ForceNew: false, + ValidateFunc: validation.StringInSlice([]string{"Dedicated"}, false), + }, + "log": { Type: schema.TypeSet, Optional: true, @@ -234,6 +241,14 @@ func resourceArmMonitorDiagnosticSettingCreateUpdate(d *schema.ResourceData, met valid = true } + if v := d.Get("log_analytics_destination_type").(string); v != "" { + if workspaceId != "" { + properties.DiagnosticSettings.LogAnalyticsDestinationType = &v + } else { + return fmt.Errorf("`log_analytics_workspace_id` must be set for `log_analytics_destination_type` to be used") + } + } + if !valid { return fmt.Errorf("Either a `eventhub_authorization_rule_id`, `log_analytics_workspace_id` or `storage_account_id` must be set") } @@ -287,6 +302,8 @@ func resourceArmMonitorDiagnosticSettingRead(d *schema.ResourceData, meta interf d.Set("log_analytics_workspace_id", resp.WorkspaceID) d.Set("storage_account_id", resp.StorageAccountID) + d.Set("log_analytics_destination_type", resp.LogAnalyticsDestinationType) + if err := d.Set("log", flattenMonitorDiagnosticLogs(resp.Logs)); err != nil { return fmt.Errorf("Error setting `log`: %+v", err) } diff --git a/azurerm/resource_arm_monitor_diagnostic_setting_test.go b/azurerm/resource_arm_monitor_diagnostic_setting_test.go index 33a694fc8d46..2ccd6a14a6a5 100644 --- a/azurerm/resource_arm_monitor_diagnostic_setting_test.go +++ b/azurerm/resource_arm_monitor_diagnostic_setting_test.go @@ -101,6 +101,39 @@ func TestAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspace(t *testing.T) }) } +func TestAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspaceDedicated(t *testing.T) { + resourceName := "azurerm_monitor_diagnostic_setting.test" + ri := acctest.RandIntRange(10000, 99999) + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMMonitorDiagnosticSettingDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspaceDedicated(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMMonitorDiagnosticSettingExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "log_analytics_workspace_id"), + resource.TestCheckResourceAttr(resourceName, "log_analytics_destination_type", "Dedicated"), + resource.TestCheckResourceAttr(resourceName, "log.#", "3"), + resource.TestCheckResourceAttr(resourceName, "log.3188484811.category", "ActivityRuns"), + resource.TestCheckResourceAttr(resourceName, "log.595859111.category", "PipelineRuns"), + resource.TestCheckResourceAttr(resourceName, "log.2542277390.category", "TriggerRuns"), + resource.TestCheckResourceAttr(resourceName, "metric.#", "1"), + resource.TestCheckResourceAttr(resourceName, "metric.4109484471.category", "AllMetrics"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMMonitorDiagnosticSetting_storageAccount(t *testing.T) { resourceName := "azurerm_monitor_diagnostic_setting.test" ri := acctest.RandIntRange(10000, 99999) @@ -338,6 +371,74 @@ resource "azurerm_monitor_diagnostic_setting" "test" { `, rInt, location, rInt, rInt, rInt) } +func testAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspaceDedicated(rInt int, location string) string { + return fmt.Sprintf(` +data "azurerm_client_config" "current" {} + +resource "azurerm_resource_group" "test" { + name = "acctest%d" + location = "%s" +} + +resource "azurerm_log_analytics_workspace" "test" { + name = "acctestlaw%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "PerGB2018" + retention_in_days = 30 +} + +resource "azurerm_data_factory" "test" { + name = "acctestdf%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_monitor_diagnostic_setting" "test" { + name = "acctestds%d" + target_resource_id = "${azurerm_data_factory.test.id}" + log_analytics_workspace_id = "${azurerm_log_analytics_workspace.test.id}" + + log_analytics_destination_type = "Dedicated" + + log { + category = "ActivityRuns" + + retention_policy { + enabled = false + } + } + + log { + category = "PipelineRuns" + enabled = false + + retention_policy { + enabled = false + } + } + + log { + category = "TriggerRuns" + enabled = false + + retention_policy { + enabled = false + } + } + + metric { + category = "AllMetrics" + enabled = false + + retention_policy { + enabled = false + } + } +} +`, rInt, location, rInt, rInt, rInt) +} + func testAccAzureRMMonitorDiagnosticSetting_storageAccount(rInt int, location string) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} diff --git a/website/docs/r/monitor_diagnostic_setting.html.markdown b/website/docs/r/monitor_diagnostic_setting.html.markdown index a5dd600012dd..99db90eacbd6 100644 --- a/website/docs/r/monitor_diagnostic_setting.html.markdown +++ b/website/docs/r/monitor_diagnostic_setting.html.markdown @@ -87,6 +87,10 @@ The following arguments are supported: -> **NOTE:** One of `eventhub_authorization_rule_id`, `log_analytics_workspace_id` and `storage_account_id` must be specified. +* `log_analytics_destination_type` - (Optional) When set to 'Dedicated' logs sent to a Log Analytics workspace will go into resource specific tables, instead of the legacy AzureDiagnostics table. + +-> **NOTE:** This setting will only have an effect if a `log_analytics_workspace_id` is provided, and the resource is available for resource-specific logs. As of July 2019, this only includes Azure Data Factory. Please [see the documentation](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/diagnostic-logs-stream-log-store#azure-diagnostics-vs-resource-specific) for more information. + --- A `log` block supports the following: