Skip to content

Commit

Permalink
azurerm_automation_software_update_configuration - fix issue about …
Browse files Browse the repository at this point in the history
…`monthly_occurrence` is not allowed to be set to `-1` (#25574)

* fix gh issue 25550

* Update internal/services/automation/automation_software_update_configuration_resource.go

---------

Co-authored-by: kt <[email protected]>
  • Loading branch information
sinbai and katbyte authored Oct 24, 2024
1 parent 06d4754 commit b588ba0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ func (m SoftwareUpdateConfigurationResource) Arguments() map[string]*pluginsdk.S
"occurrence": {
Type: pluginsdk.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(1, 5),
ValidateFunc: validation.IntInSlice([]int{1, 2, 3, 4, -1}), // -1 is last week and 5 is invalid
},

"day": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ func TestAccSoftwareUpdateConfiguration_linuxBasic(t *testing.T) {
})
}

func TestAccSoftwareUpdateConfiguration_occurrence(t *testing.T) {
data := acceptance.BuildTestData(t, automation.SoftwareUpdateConfigurationResource{}.ResourceType(), "test")
r := newSoftwareUpdateConfigurationResource()
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.monthOccurrence(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// scheduleInfo.advancedSchedule always returns null - https://github.com/Azure/azure-rest-api-specs/issues/24436
data.ImportStep("schedule.0.advanced", "schedule.0.monthly_occurrence"),
})
}

func TestAccSoftwareUpdateConfiguration_linuxComplete(t *testing.T) {
data := acceptance.BuildTestData(t, automation.SoftwareUpdateConfigurationResource{}.ResourceType(), "test")
r := newSoftwareUpdateConfigurationResource()
Expand Down Expand Up @@ -343,6 +358,55 @@ resource "azurerm_automation_software_update_configuration" "test" {
`, a.template(data), data.RandomInteger)
}

func (a SoftwareUpdateConfigurationResource) monthOccurrence(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_automation_software_update_configuration" "test" {
automation_account_id = azurerm_automation_account.test.id
name = "acctest-suc-%[2]d"
linux {
classifications_included = ["Critical", "Security"]
excluded_packages = ["apt"]
included_packages = ["vim"]
reboot = "RebootOnly"
}
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"
expiry_time = "%[4]s"
is_enabled = true
interval = 1
frequency = "Month"
time_zone = "Etc/UTC"
monthly_occurrence {
occurrence = -1
day = "Tuesday"
}
}
depends_on = [azurerm_log_analytics_linked_service.test]
}
`, a.template(data), data.RandomInteger, a.startTime, a.expireTime)
}

func (a SoftwareUpdateConfigurationResource) linuxComplete(data acceptance.TestData) string {
return fmt.Sprintf(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ The `monthly_occurrence` block supports the following:

* `day` - (Required) Day of the occurrence. Must be one of `Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday`, `Saturday`, `Sunday`.

* `occurrence` - (Required) Occurrence of the week within the month. Must be between `1` and `5`. `-1` for last week within the month.
* `occurrence` - (Required) Occurrence of the week within the month. Must be between `1` and `4`. `-1` for last week within the month.

## Attributes Reference

Expand Down

0 comments on commit b588ba0

Please sign in to comment.