Skip to content

Commit

Permalink
Allow recurring_schedule.time_of_day to be set to 00:00 (GoogleClou…
Browse files Browse the repository at this point in the history
  • Loading branch information
shuyama1 authored and betsy-lichtenberg committed Apr 25, 2022
1 parent 6bd66a6 commit 0f29edb
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mmv1/products/osconfig/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides
primary_resource_id: "patch"
vars:
patch_deployment_id: "patch-deploy"
- !ruby/object:Provider::Terraform::Examples
name: "os_config_patch_deployment_daily_midnight"
primary_resource_id: "patch"
vars:
patch_deployment_id: "patch-deploy"
- !ruby/object:Provider::Terraform::Examples
name: "os_config_patch_deployment_instance"
primary_resource_id: "patch"
Expand All @@ -41,6 +46,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides
patchDeploymentId: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
regex: "(?:(?:[-a-z0-9]{1,63}\\.)*(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?):)?(?:[0-9]{1,19}|(?:[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])?))"
recurringSchedule.timeOfDay: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/os_config_patch_deployment_recurring_schedule_time_of_day.go.erb'
send_empty_value: true
recurringSchedule.timeOfDay.hours: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.IntBetween(0,23)'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<%# The license inside this block applies to this file.
# Copyright 2022 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
transformed := make(map[string]interface{})
transformed["hours"] =
flattenOSConfigPatchDeploymentRecurringScheduleTimeOfDayHours(original["hours"], d, config)
transformed["minutes"] =
flattenOSConfigPatchDeploymentRecurringScheduleTimeOfDayMinutes(original["minutes"], d, config)
transformed["seconds"] =
flattenOSConfigPatchDeploymentRecurringScheduleTimeOfDaySeconds(original["seconds"], d, config)
transformed["nanos"] =
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 {
if intVal, err := stringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenOSConfigPatchDeploymentRecurringScheduleTimeOfDayMinutes(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := stringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenOSConfigPatchDeploymentRecurringScheduleTimeOfDaySeconds(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := stringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenOSConfigPatchDeploymentRecurringScheduleTimeOfDayNanos(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := stringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "google_os_config_patch_deployment" "<%= ctx[:primary_resource_id] %>" {
patch_deployment_id = "<%= ctx[:vars]['patch_deployment_id'] %>"

instance_filter {
all = true
}

recurring_schedule {
time_zone {
id = "America/New_York"
}

time_of_day {
hours = 0
minutes = 0
seconds = 0
nanos = 0
}
}
}

0 comments on commit 0f29edb

Please sign in to comment.