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 issue about monthly_occurrence is not allowed to be set to -1 #25574

Merged
merged 2 commits into from
Oct 24, 2024
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 @@ -628,7 +628,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 @@ -340,6 +355,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 @@ -208,7 +208,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
Loading