diff --git a/mmv1/products/osconfig/terraform.yaml b/mmv1/products/osconfig/terraform.yaml index 373d6bb3d8ef..090f2e46c4da 100644 --- a/mmv1/products/osconfig/terraform.yaml +++ b/mmv1/products/osconfig/terraform.yaml @@ -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" @@ -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)' diff --git a/mmv1/templates/terraform/custom_flatten/os_config_patch_deployment_recurring_schedule_time_of_day.go.erb b/mmv1/templates/terraform/custom_flatten/os_config_patch_deployment_recurring_schedule_time_of_day.go.erb new file mode 100644 index 000000000000..e4655ff0727f --- /dev/null +++ b/mmv1/templates/terraform/custom_flatten/os_config_patch_deployment_recurring_schedule_time_of_day.go.erb @@ -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 +} \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/os_config_patch_deployment_daily_midnight.tf.erb b/mmv1/templates/terraform/examples/os_config_patch_deployment_daily_midnight.tf.erb new file mode 100644 index 000000000000..3794ce1bd714 --- /dev/null +++ b/mmv1/templates/terraform/examples/os_config_patch_deployment_daily_midnight.tf.erb @@ -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 + } + } +} \ No newline at end of file