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

Add nil check to recurring_schedule in google_os_config_patch_deployment #2481

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
3 changes: 3 additions & 0 deletions .changelog/3974.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
osconfig: fixed a potential crash in `google_os_config_patch_deployment` due to an unchecked nil value in `recurring_schedule`
````
12 changes: 7 additions & 5 deletions google-beta/resource_os_config_patch_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3243,11 +3243,13 @@ func expandOSConfigPatchDeploymentRolloutDisruptionBudgetPercentage(v interface{
}

func resourceOSConfigPatchDeploymentEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
schedule := obj["recurringSchedule"].(map[string]interface{})
if schedule["monthly"] != nil {
obj["recurringSchedule"].(map[string]interface{})["frequency"] = "MONTHLY"
} else if schedule["weekly"] != nil {
obj["recurringSchedule"].(map[string]interface{})["frequency"] = "WEEKLY"
if obj["recurringSchedule"] != nil {
schedule := obj["recurringSchedule"].(map[string]interface{})
if schedule["monthly"] != nil {
obj["recurringSchedule"].(map[string]interface{})["frequency"] = "MONTHLY"
} else if schedule["weekly"] != nil {
obj["recurringSchedule"].(map[string]interface{})["frequency"] = "WEEKLY"
}
}

if obj["patchConfig"] != nil {
Expand Down
14 changes: 2 additions & 12 deletions google-beta/resource_os_config_patch_deployment_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,8 @@ resource "google_os_config_patch_deployment" "patch" {
all = true
}
recurring_schedule {
time_zone {
id = "America/New_York"
}
time_of_day {
hours = 1
}
weekly {
day_of_week = "MONDAY"
}
one_time_schedule {
execute_time = "2020-10-10T10:10:10.045123456Z"
}
}
`, context)
Expand Down
14 changes: 2 additions & 12 deletions website/docs/r/os_config_patch_deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,8 @@ resource "google_os_config_patch_deployment" "patch" {
all = true
}

recurring_schedule {
time_zone {
id = "America/New_York"
}

time_of_day {
hours = 1
}

weekly {
day_of_week = "MONDAY"
}
one_time_schedule {
execute_time = "2020-10-10T10:10:10.045123456Z"
}
}
```
Expand Down