Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow recurring_schedule.time_of_day to be set to 00:00 #11293

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/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/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%2Fgit.luolix.top%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%2Fgit.luolix.top%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