diff --git a/.changelog/3974.txt b/.changelog/3974.txt new file mode 100644 index 00000000000..2cc7c883530 --- /dev/null +++ b/.changelog/3974.txt @@ -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` +```` diff --git a/google/resource_os_config_patch_deployment.go b/google/resource_os_config_patch_deployment.go index 91c91d783bc..441d553e53e 100644 --- a/google/resource_os_config_patch_deployment.go +++ b/google/resource_os_config_patch_deployment.go @@ -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 { diff --git a/google/resource_os_config_patch_deployment_generated_test.go b/google/resource_os_config_patch_deployment_generated_test.go index 0abe249bf9e..2a7307bc938 100644 --- a/google/resource_os_config_patch_deployment_generated_test.go +++ b/google/resource_os_config_patch_deployment_generated_test.go @@ -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) diff --git a/website/docs/r/os_config_patch_deployment.html.markdown b/website/docs/r/os_config_patch_deployment.html.markdown index 4d3a25ea540..678ec1f346c 100644 --- a/website/docs/r/os_config_patch_deployment.html.markdown +++ b/website/docs/r/os_config_patch_deployment.html.markdown @@ -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" } } ```