diff --git a/.changelog/5822.txt b/.changelog/5822.txt new file mode 100644 index 00000000000..4b5c5deeeab --- /dev/null +++ b/.changelog/5822.txt @@ -0,0 +1,3 @@ +```release-note:bug +osconfig: fixed a bug where `recurring_schedule.time_of_day` can not be set to 12am exact time in `google_os_config_patch_deployment` resource +``` diff --git a/google/resource_os_config_patch_deployment.go b/google/resource_os_config_patch_deployment.go index 3d97af061f5..27291ff1569 100644 --- a/google/resource_os_config_patch_deployment.go +++ b/google/resource_os_config_patch_deployment.go @@ -1800,9 +1800,6 @@ func flattenOSConfigPatchDeploymentRecurringScheduleTimeOfDay(v interface{}, d * return nil } original := v.(map[string]interface{}) - if len(original) == 0 { - return nil - } transformed := make(map[string]interface{}) transformed["hours"] = flattenOSConfigPatchDeploymentRecurringScheduleTimeOfDayHours(original["hours"], d, config) @@ -1814,6 +1811,7 @@ func flattenOSConfigPatchDeploymentRecurringScheduleTimeOfDay(v interface{}, d * flattenOSConfigPatchDeploymentRecurringScheduleTimeOfDayNanos(original["nanos"], d, config) return []interface{}{transformed} } + func flattenOSConfigPatchDeploymentRecurringScheduleTimeOfDayHours(v interface{}, d *schema.ResourceData, config *Config) interface{} { // Handles the string fixed64 format if strVal, ok := v.(string); ok { @@ -2962,7 +2960,7 @@ func expandOSConfigPatchDeploymentRecurringSchedule(v interface{}, d TerraformRe transformedTimeOfDay, err := expandOSConfigPatchDeploymentRecurringScheduleTimeOfDay(original["time_of_day"], d, config) if err != nil { return nil, err - } else if val := reflect.ValueOf(transformedTimeOfDay); val.IsValid() && !isEmptyValue(val) { + } else { transformed["timeOfDay"] = transformedTimeOfDay } diff --git a/google/resource_os_config_patch_deployment_generated_test.go b/google/resource_os_config_patch_deployment_generated_test.go index 9947b8e54d4..16cd6d04319 100644 --- a/google/resource_os_config_patch_deployment_generated_test.go +++ b/google/resource_os_config_patch_deployment_generated_test.go @@ -114,6 +114,56 @@ resource "google_os_config_patch_deployment" "patch" { `, context) } +func TestAccOSConfigPatchDeployment_osConfigPatchDeploymentDailyMidnightExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckOSConfigPatchDeploymentDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccOSConfigPatchDeployment_osConfigPatchDeploymentDailyMidnightExample(context), + }, + { + ResourceName: "google_os_config_patch_deployment.patch", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"patch_deployment_id"}, + }, + }, + }) +} + +func testAccOSConfigPatchDeployment_osConfigPatchDeploymentDailyMidnightExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_os_config_patch_deployment" "patch" { + patch_deployment_id = "tf-test-patch-deploy%{random_suffix}" + + instance_filter { + all = true + } + + recurring_schedule { + time_zone { + id = "America/New_York" + } + + time_of_day { + hours = 0 + minutes = 0 + seconds = 0 + nanos = 0 + } + } +} +`, context) +} + func TestAccOSConfigPatchDeployment_osConfigPatchDeploymentInstanceExample(t *testing.T) { t.Parallel() diff --git a/website/docs/r/os_config_patch_deployment.html.markdown b/website/docs/r/os_config_patch_deployment.html.markdown index 0246ad1d410..5580472a2f0 100644 --- a/website/docs/r/os_config_patch_deployment.html.markdown +++ b/website/docs/r/os_config_patch_deployment.html.markdown @@ -83,6 +83,36 @@ resource "google_os_config_patch_deployment" "patch" { } } ``` +
+## Example Usage - Os Config Patch Deployment Daily Midnight + + +```hcl +resource "google_os_config_patch_deployment" "patch" { + patch_deployment_id = "patch-deploy" + + instance_filter { + all = true + } + + recurring_schedule { + time_zone { + id = "America/New_York" + } + + time_of_day { + hours = 0 + minutes = 0 + seconds = 0 + nanos = 0 + } + } +} +```