Skip to content

Commit

Permalink
azurerm_automanage_configuration - support new property block `log_…
Browse files Browse the repository at this point in the history
…analytics_enabled` (#22121)
  • Loading branch information
liuwuliuyun authored Jun 12, 2023
1 parent e0477f2 commit 2b8e0f8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
16 changes: 16 additions & 0 deletions internal/services/automanage/automanage_configuration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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(`
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/automanage_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2b8e0f8

Please sign in to comment.