Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_automation_software_update_configuration: fix panic issue #21311

Merged
merged 4 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 = <<CONTENT
# Some test content
# for Terraform acceptance test
CONTENT
tags = {
ENV = "runbook_test"
}
}

%s

resource "azurerm_automation_software_update_configuration" "test" {
automation_account_id = azurerm_automation_account.test.id
name = "acctest-suc-%[2]d"
operating_system = "Linux"

linux {
classification_included = "Security"
excluded_packages = ["apt"]
included_packages = ["vim"]
reboot = "IfRequired"
}

duration = "PT1H1M1S"
virtual_machine_ids = []

target {
azure_query {
scope = [azurerm_resource_group.test.id]
locations = [azurerm_resource_group.test.location]
}

non_azure_query {
function_alias = "savedSearch1"
workspace_id = azurerm_log_analytics_workspace.test.id
}
}

schedule {
description = "foo-schedule"
start_time = "%[3]s"
is_enabled = true
interval = 1
frequency = "Hour"
time_zone = "Etc/UTC"
advanced_week_days = ["Monday", "Tuesday"]
advanced_month_days = [1, 10, 15]
monthly_occurrence {
occurrence = 1
day = "Tuesday"
}
}

pre_task {
source = azurerm_automation_runbook.test.name
parameters = {
COMPUTERNAME = "Foo"
}
}

post_task {
source = azurerm_automation_runbook.test.name
parameters = {
COMPUTERNAME = "Foo"
}
}

depends_on = [azurerm_log_analytics_linked_service.test]
}
`, a.template(data), data.RandomInteger, a.startTime, a.expireTime)
}

func (a SoftwareUpdateConfigurationResource) update(data acceptance.TestData) string {
return fmt.Sprintf(`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,41 @@ provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
resource "azurerm_resource_group" "example" {
name = "example-rg"
location = "East US"
}

resource "azurerm_automation_account" "test" {
resource "azurerm_automation_account" "example" {
name = "example"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku_name = "Basic"
}

resource "azurerm_automation_runbook" "example" {
name = "Get-AzureVMTutorial"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
automation_account_name = azurerm_automation_account.example.name

log_verbose = "true"
log_progress = "true"
description = "This is a example runbook for terraform acceptance example"
runbook_type = "Python3"

content = <<CONTENT
# Some example content
# for Terraform acceptance example
CONTENT
tags = {
ENV = "runbook_test"
}
}

resource "azurerm_automation_software_update_configuration" "example" {
name = "example"
automation_account_id = azurerm_automation_account.test.id
automation_account_id = azurerm_automation_account.example.id
operating_system = "Linux"

linux {
Expand All @@ -41,6 +61,13 @@ resource "azurerm_automation_software_update_configuration" "example" {
reboot = "IfRequired"
}

pre_task {
source = azurerm_automation_runbook.example.name
parameters = {
COMPUTER_NAME = "Foo"
}
}

duration = "PT2H2M2S"
}
```
Expand Down