From 2b8e0f8a5db5f397f953b98a5af46dab640b6baf Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Tue, 13 Jun 2023 07:37:55 +0800 Subject: [PATCH] `azurerm_automanage_configuration` - support new property block `log_analytics_enabled` (#22121) --- .../automanage_configuration_resource.go | 16 ++++++++ .../automanage_configuration_resource_test.go | 37 +++++++++++++++++++ .../r/automanage_configuration.html.markdown | 3 ++ 3 files changed, 56 insertions(+) diff --git a/internal/services/automanage/automanage_configuration_resource.go b/internal/services/automanage/automanage_configuration_resource.go index 9743fb9a57d5..99b88fc22697 100644 --- a/internal/services/automanage/automanage_configuration_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -52,6 +52,7 @@ type ConfigurationModel struct { Antimalware []AntimalwareConfiguration `tfschema:"antimalware"` AzureSecurityBaseline []AzureSecurityBaselineConfiguration `tfschema:"azure_security_baseline"` Backup []BackupConfiguration `tfschema:"backup"` + LogAnalyticsEnabled bool `tfschema:"log_analytics_enabled"` AutomationAccountEnabled bool `tfschema:"automation_account_enabled"` BootDiagnosticsEnabled bool `tfschema:"boot_diagnostics_enabled"` DefenderForCloudEnabled bool `tfschema:"defender_for_cloud_enabled"` @@ -433,6 +434,13 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem Default: false, }, + // "LogAnalytics/Enable": boolean, + "log_analytics_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + // "Alerts/AutomanageStatusChanges/Enable": boolean, "status_change_alert_enabled": { Type: pluginsdk.TypeBool, @@ -571,6 +579,10 @@ func (r AutoManageConfigurationResource) Read() sdk.ResourceFunc { state.GuestConfigurationEnabled = val.(bool) } + if val, ok := configMap["LogAnalytics/Enable"]; ok { + state.LogAnalyticsEnabled = val.(bool) + } + if val, ok := configMap["Alerts/AutomanageStatusChanges/Enable"]; ok { state.StatusChangeAlertEnabled = val.(bool) } @@ -695,6 +707,10 @@ func expandAutomanageConfigurationProfile(model ConfigurationModel) *map[string] jsonConfig["GuestConfiguration/Enable"] = model.GuestConfigurationEnabled } + if model.LogAnalyticsEnabled { + jsonConfig["LogAnalytics/Enable"] = model.LogAnalyticsEnabled + } + if model.StatusChangeAlertEnabled { jsonConfig["Alerts/AutomanageStatusChanges/Enable"] = model.StatusChangeAlertEnabled } diff --git a/internal/services/automanage/automanage_configuration_resource_test.go b/internal/services/automanage/automanage_configuration_resource_test.go index 14986e27402d..de7d352c81b7 100644 --- a/internal/services/automanage/automanage_configuration_resource_test.go +++ b/internal/services/automanage/automanage_configuration_resource_test.go @@ -176,6 +176,29 @@ func TestAccAutoManageConfigurationProfile_backup(t *testing.T) { }) } +func TestAccAutoManageConfigurationProfile_logAnalytics(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_automanage_configuration", "test") + r := AutoManageConfigurationProfileResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.logAnalytics(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("log_analytics_enabled").HasValue("true"), + ), + }, + data.ImportStep(), + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("log_analytics_enabled").HasValue("false"), + ), + }, + data.ImportStep(), + }) +} + func TestAccAutoManageConfigurationProfile_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_automanage_configuration", "test") r := AutoManageConfigurationProfileResource{} @@ -302,6 +325,20 @@ resource "azurerm_automanage_configuration" "test" { `, template, data.RandomInteger, data.Locations.Primary) } +func (r AutoManageConfigurationProfileResource) logAnalytics(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_automanage_configuration" "test" { + name = "acctest-amcp-%d" + resource_group_name = azurerm_resource_group.test.name + location = "%s" + log_analytics_enabled = true +} +`, template, data.RandomInteger, data.Locations.Primary) +} + func (r AutoManageConfigurationProfileResource) requiresImport(data acceptance.TestData) string { config := r.antimalware(data) return fmt.Sprintf(` diff --git a/website/docs/r/automanage_configuration.html.markdown b/website/docs/r/automanage_configuration.html.markdown index a2759a1ab6fa..9e16a95804fd 100644 --- a/website/docs/r/automanage_configuration.html.markdown +++ b/website/docs/r/automanage_configuration.html.markdown @@ -79,6 +79,7 @@ resource "azurerm_automanage_configuration" "example" { boot_diagnostics_enabled = true defender_for_cloud_enabled = true guest_configuration_enabled = true + log_analytics_enabled = true status_change_alert_enabled = true tags = { @@ -111,6 +112,8 @@ The following arguments are supported: * `guest_configuration_enabled` - (Optional) Whether the guest configuration is enabled. Defaults to `false`. +* `log_analytics_enabled` - (Optional) Whether log analytics are enabled. Defaults to `false`. + * `status_change_alert_enabled` - (Optional) Whether the status change alert is enabled. Defaults to `false`. * `tags` - (Optional) A mapping of tags to assign to the resource.