Skip to content

Commit

Permalink
Add nil check to recurring_schedule in google_os_config_patch_deploym…
Browse files Browse the repository at this point in the history
…ent (#3974) (#2481)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Sep 14, 2020
1 parent 0a81851 commit efd2322
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
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

0 comments on commit efd2322

Please sign in to comment.