Skip to content

Commit

Permalink
Allow recurring_schedule.time_of_day to be set to 00:00 (#5822) (#4127
Browse files Browse the repository at this point in the history
)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Mar 16, 2022
1 parent b788478 commit 3245840
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/5822.txt
Original file line number Diff line number Diff line change
@@ -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
```
6 changes: 2 additions & 4 deletions google-beta/resource_os_config_patch_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
50 changes: 50 additions & 0 deletions google-beta/resource_os_config_patch_deployment_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
30 changes: 30 additions & 0 deletions website/docs/r/os_config_patch_deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@ resource "google_os_config_patch_deployment" "patch" {
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=os_config_patch_deployment_daily_midnight&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## 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
}
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=os_config_patch_deployment_instance&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
Expand Down

0 comments on commit 3245840

Please sign in to comment.