From ad35a449bc23a46ccd8ece174b2884c0b7892f9e Mon Sep 17 00:00:00 2001 From: Xu Wu Date: Tue, 11 Apr 2023 15:51:11 +0800 Subject: [PATCH] `azurerm_automation_software_update_configuration`: fix panic issue (#21311) * fix panic issue * add unit test for task in software update configuration * update software udpate configuration markdown example with tasks * terrafmt doc --- ..._software_update_configuration_resource.go | 2 + ...ware_update_configuration_resource_test.go | 102 ++++++++++++++++++ ...oftware_update_configuration.html.markdown | 37 ++++++- 3 files changed, 136 insertions(+), 5 deletions(-) diff --git a/internal/services/automation/automation_software_update_configuration_resource.go b/internal/services/automation/automation_software_update_configuration_resource.go index 7f1593b82c6b..9d98a526ce3e 100644 --- a/internal/services/automation/automation_software_update_configuration_resource.go +++ b/internal/services/automation/automation_software_update_configuration_resource.go @@ -86,7 +86,9 @@ func updateTaskFromSDK(prop *softwareupdateconfiguration.TaskProperties) (res [] res = append(res, UpdateTask{ Source: utils.NormalizeNilableString(prop.Source), }) + if prop.Parameters != nil { + res[0].Parameters = map[string]string{} for k, v := range *prop.Parameters { res[0].Parameters[k] = v } diff --git a/internal/services/automation/automation_software_update_configuration_resource_test.go b/internal/services/automation/automation_software_update_configuration_resource_test.go index 7b72f6b800d7..0811fff756e0 100644 --- a/internal/services/automation/automation_software_update_configuration_resource_test.go +++ b/internal/services/automation/automation_software_update_configuration_resource_test.go @@ -58,6 +58,21 @@ func TestAccSoftwareUpdateConfiguration_basic(t *testing.T) { }) } +func TestAccSoftwareUpdateConfiguration_withTask(t *testing.T) { + data := acceptance.BuildTestData(t, automation.SoftwareUpdateConfigurationResource{}.ResourceType(), "test") + r := newSoftwareUpdateConfigurationResource() + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.withTask(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + // scheduleInfo.advancedSchedule always return null + data.ImportStep("schedule.0.advanced", "schedule.0.monthly_occurrence"), + }) +} + func TestAccSoftwareUpdateConfiguration_defaultTimeZone(t *testing.T) { data := acceptance.BuildTestData(t, automation.SoftwareUpdateConfigurationResource{}.ResourceType(), "test") r := newSoftwareUpdateConfigurationResource() @@ -224,6 +239,93 @@ resource "azurerm_automation_software_update_configuration" "test" { `, a.template(data), data.RandomInteger, a.startTime, a.expireTime) } +func (a SoftwareUpdateConfigurationResource) withTask(data acceptance.TestData) string { + return fmt.Sprintf(` + + +resource "azurerm_automation_runbook" "test" { + name = "Get-AzureVMTutorial" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + automation_account_name = azurerm_automation_account.test.name + + log_verbose = "true" + log_progress = "true" + description = "This is a test runbook for terraform acceptance test" + runbook_type = "PowerShell" + + content = <