forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly handle AutomatedBackupPolicy midnight start time (hours = 0) (…
…GoogleCloudPlatform#8337) * Properly handle ABP midnight (hours = 0) * Add ExpectNonEmptyPlan to test * Simplify custom flatten
- Loading branch information
1 parent
6c9f62f
commit 4d52a4d
Showing
3 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...m/custom_flatten/alloydb_cluster_input_automated_backup_policy_start_times_flatten.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<%# The license inside this block applies to this file. | ||
# Copyright 2023 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 *transport_tpg.Config) interface{} { | ||
if v == nil { | ||
return v | ||
} | ||
l := v.([]interface{}) | ||
transformed := make([]interface{}, 0, len(l)) | ||
for _, raw := range l { | ||
original := raw.(map[string]interface{}) | ||
if len(original) < 1 { | ||
// If no start times exist, that means we take backups at midnight. This is represented as 0's all around. | ||
return append(transformed, map[string]interface{}{}) | ||
} | ||
transformed = append(transformed, map[string]interface{}{ | ||
"hours": flattenAlloydbClusterAutomatedBackupPolicyWeeklyScheduleStartTimesHours(original["hours"], d, config), | ||
"minutes": flattenAlloydbClusterAutomatedBackupPolicyWeeklyScheduleStartTimesMinutes(original["minutes"], d, config), | ||
"seconds": flattenAlloydbClusterAutomatedBackupPolicyWeeklyScheduleStartTimesSeconds(original["seconds"], d, config), | ||
"nanos": flattenAlloydbClusterAutomatedBackupPolicyWeeklyScheduleStartTimesNanos(original["nanos"], d, config), | ||
}) | ||
} | ||
return transformed | ||
} | ||
|
||
func flattenAlloydbClusterAutomatedBackupPolicyWeeklyScheduleStartTimesHours(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
// Handles the string fixed64 format | ||
if strVal, ok := v.(string); ok { | ||
if intVal, err := tpgresource.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 flattenAlloydbClusterAutomatedBackupPolicyWeeklyScheduleStartTimesMinutes(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
// Handles the string fixed64 format | ||
if strVal, ok := v.(string); ok { | ||
if intVal, err := tpgresource.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 flattenAlloydbClusterAutomatedBackupPolicyWeeklyScheduleStartTimesSeconds(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
// Handles the string fixed64 format | ||
if strVal, ok := v.(string); ok { | ||
if intVal, err := tpgresource.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 flattenAlloydbClusterAutomatedBackupPolicyWeeklyScheduleStartTimesNanos(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
// Handles the string fixed64 format | ||
if strVal, ok := v.(string); ok { | ||
if intVal, err := tpgresource.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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters