Skip to content

Commit bf3ff3a

Browse files
Add nil check to recurring_schedule in google_os_config_patch_deployment (#3974) (#7265)
Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent a37a42e commit bf3ff3a

File tree

4 files changed

+14
-29
lines changed

4 files changed

+14
-29
lines changed

.changelog/3974.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
osconfig: fixed a potential crash in `google_os_config_patch_deployment` due to an unchecked nil value in `recurring_schedule`
3+
````

google/resource_os_config_patch_deployment.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3243,11 +3243,13 @@ func expandOSConfigPatchDeploymentRolloutDisruptionBudgetPercentage(v interface{
32433243
}
32443244

32453245
func resourceOSConfigPatchDeploymentEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
3246-
schedule := obj["recurringSchedule"].(map[string]interface{})
3247-
if schedule["monthly"] != nil {
3248-
obj["recurringSchedule"].(map[string]interface{})["frequency"] = "MONTHLY"
3249-
} else if schedule["weekly"] != nil {
3250-
obj["recurringSchedule"].(map[string]interface{})["frequency"] = "WEEKLY"
3246+
if obj["recurringSchedule"] != nil {
3247+
schedule := obj["recurringSchedule"].(map[string]interface{})
3248+
if schedule["monthly"] != nil {
3249+
obj["recurringSchedule"].(map[string]interface{})["frequency"] = "MONTHLY"
3250+
} else if schedule["weekly"] != nil {
3251+
obj["recurringSchedule"].(map[string]interface{})["frequency"] = "WEEKLY"
3252+
}
32513253
}
32523254

32533255
if obj["patchConfig"] != nil {

google/resource_os_config_patch_deployment_generated_test.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,8 @@ resource "google_os_config_patch_deployment" "patch" {
5757
all = true
5858
}
5959
60-
recurring_schedule {
61-
time_zone {
62-
id = "America/New_York"
63-
}
64-
65-
time_of_day {
66-
hours = 1
67-
}
68-
69-
weekly {
70-
day_of_week = "MONDAY"
71-
}
60+
one_time_schedule {
61+
execute_time = "2020-10-10T10:10:10.045123456Z"
7262
}
7363
}
7464
`, context)

website/docs/r/os_config_patch_deployment.html.markdown

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,8 @@ resource "google_os_config_patch_deployment" "patch" {
4848
all = true
4949
}
5050
51-
recurring_schedule {
52-
time_zone {
53-
id = "America/New_York"
54-
}
55-
56-
time_of_day {
57-
hours = 1
58-
}
59-
60-
weekly {
61-
day_of_week = "MONDAY"
62-
}
51+
one_time_schedule {
52+
execute_time = "2020-10-10T10:10:10.045123456Z"
6353
}
6454
}
6555
```

0 commit comments

Comments
 (0)