From f19833eb467f28de84f9d6e2b5cd27f98e3538c3 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Thu, 29 Oct 2020 20:37:58 +0000 Subject: [PATCH] Convert all the range values to be doubles and add a test that uses a double. (#4162) Signed-off-by: Modular Magician --- .changelog/4162.txt | 3 + google/resource_monitoring_slo.go | 137 ++---------------- .../resource_monitoring_slo_generated_test.go | 15 +- website/docs/r/monitoring_slo.html.markdown | 15 +- 4 files changed, 29 insertions(+), 141 deletions(-) create mode 100644 .changelog/4162.txt diff --git a/.changelog/4162.txt b/.changelog/4162.txt new file mode 100644 index 00000000000..0fde0f29931 --- /dev/null +++ b/.changelog/4162.txt @@ -0,0 +1,3 @@ +```release-note:bug +monitoring: Fixed type of `google_monitoring_slo`'s `range` values - some `range` values are doubles, others are integers. +``` diff --git a/google/resource_monitoring_slo.go b/google/resource_monitoring_slo.go index 3e1cf9816b3..e19e9436e2c 100644 --- a/google/resource_monitoring_slo.go +++ b/google/resource_monitoring_slo.go @@ -18,7 +18,6 @@ import ( "fmt" "log" "reflect" - "strconv" "strings" "time" @@ -212,7 +211,7 @@ just one of min or max.`, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "max": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Optional: true, Description: `max value for the range (inclusive). If not given, will be set to "infinity", defining an open range @@ -220,7 +219,7 @@ will be set to "infinity", defining an open range AtLeastOneOf: []string{"request_based_sli.0.distribution_cut.0.range.0.min", "request_based_sli.0.distribution_cut.0.range.0.max"}, }, "min": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Optional: true, Description: `Min value for the range (inclusive). If not given, will be set to "-infinity", defining an open range @@ -440,7 +439,7 @@ just one of min or max.`, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "max": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Optional: true, Description: `max value for the range (inclusive). If not given, will be set to "infinity", defining an open range @@ -448,7 +447,7 @@ will be set to "infinity", defining an open range AtLeastOneOf: []string{"windows_based_sli.0.good_total_ratio_threshold.0.performance.0.distribution_cut.0.range.0.min", "windows_based_sli.0.good_total_ratio_threshold.0.performance.0.distribution_cut.0.range.0.max"}, }, "min": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Optional: true, Description: `Min value for the range (inclusive). If not given, will be set to "-infinity", defining an open range @@ -557,7 +556,7 @@ good service.`, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "max": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Optional: true, Description: `max value for the range (inclusive). If not given, will be set to "infinity", defining an open range @@ -565,7 +564,7 @@ will be set to "infinity", defining an open range AtLeastOneOf: []string{"windows_based_sli.0.metric_mean_in_range.0.range.0.min", "windows_based_sli.0.metric_mean_in_range.0.range.0.max"}, }, "min": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Optional: true, Description: `Min value for the range (inclusive). If not given, will be set to "-infinity", defining an open range @@ -616,7 +615,7 @@ just one of min or max. Summed value 'X' should satisfy Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "max": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Optional: true, Description: `max value for the range (inclusive). If not given, will be set to "infinity", defining an open range @@ -624,7 +623,7 @@ will be set to "infinity", defining an open range AtLeastOneOf: []string{"windows_based_sli.0.metric_sum_in_range.0.range.0.min", "windows_based_sli.0.metric_sum_in_range.0.range.0.max"}, }, "min": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Optional: true, Description: `Min value for the range (inclusive). If not given, will be set to "-infinity", defining an open range @@ -1226,37 +1225,11 @@ func flattenMonitoringSloServiceLevelIndicatorRequestBasedSliDistributionCutRang return []interface{}{transformed} } func flattenMonitoringSloServiceLevelIndicatorRequestBasedSliDistributionCutRangeMin(v interface{}, d *schema.ResourceData, config *Config) interface{} { - // Handles the string fixed64 format - if strVal, ok := v.(string); ok { - if intVal, err := strconv.ParseInt(strVal, 10, 64); 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 + return v } func flattenMonitoringSloServiceLevelIndicatorRequestBasedSliDistributionCutRangeMax(v interface{}, d *schema.ResourceData, config *Config) interface{} { - // Handles the string fixed64 format - if strVal, ok := v.(string); ok { - if intVal, err := strconv.ParseInt(strVal, 10, 64); 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 + return v } func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSli(v interface{}, d *schema.ResourceData, config *Config) interface{} { @@ -1388,37 +1361,11 @@ func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThres return []interface{}{transformed} } func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdPerformanceDistributionCutRangeMin(v interface{}, d *schema.ResourceData, config *Config) interface{} { - // Handles the string fixed64 format - if strVal, ok := v.(string); ok { - if intVal, err := strconv.ParseInt(strVal, 10, 64); 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 + return v } func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdPerformanceDistributionCutRangeMax(v interface{}, d *schema.ResourceData, config *Config) interface{} { - // Handles the string fixed64 format - if strVal, ok := v.(string); ok { - if intVal, err := strconv.ParseInt(strVal, 10, 64); 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 + return v } func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdBasicSliPerformance(v interface{}, d *schema.ResourceData, config *Config) interface{} { @@ -1513,37 +1460,11 @@ func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricMeanInRangeRa return []interface{}{transformed} } func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricMeanInRangeRangeMin(v interface{}, d *schema.ResourceData, config *Config) interface{} { - // Handles the string fixed64 format - if strVal, ok := v.(string); ok { - if intVal, err := strconv.ParseInt(strVal, 10, 64); 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 + return v } func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricMeanInRangeRangeMax(v interface{}, d *schema.ResourceData, config *Config) interface{} { - // Handles the string fixed64 format - if strVal, ok := v.(string); ok { - if intVal, err := strconv.ParseInt(strVal, 10, 64); 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 + return v } func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricSumInRange(v interface{}, d *schema.ResourceData, config *Config) interface{} { @@ -1581,37 +1502,11 @@ func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricSumInRangeRan return []interface{}{transformed} } func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricSumInRangeRangeMin(v interface{}, d *schema.ResourceData, config *Config) interface{} { - // Handles the string fixed64 format - if strVal, ok := v.(string); ok { - if intVal, err := strconv.ParseInt(strVal, 10, 64); 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 + return v } func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricSumInRangeRangeMax(v interface{}, d *schema.ResourceData, config *Config) interface{} { - // Handles the string fixed64 format - if strVal, ok := v.(string); ok { - if intVal, err := strconv.ParseInt(strVal, 10, 64); 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 + return v } func flattenMonitoringSloSloId(v interface{}, d *schema.ResourceData, config *Config) interface{} { diff --git a/google/resource_monitoring_slo_generated_test.go b/google/resource_monitoring_slo_generated_test.go index 2bb8ff709c0..9b695fa3b76 100644 --- a/google/resource_monitoring_slo_generated_test.go +++ b/google/resource_monitoring_slo_generated_test.go @@ -121,16 +121,11 @@ resource "google_monitoring_slo" "request_based_slo" { request_based_sli { distribution_cut { - distribution_filter = join(" AND ", [ - "metric.type=\"serviceruntime.googleapis.com/api/request_latencies\"", - "resource.type=\"consumed_api\"", - "resource.label.\"project_id\"=\"%{project}\"", - ]) - - range { - max = 10 - } - } + distribution_filter = "metric.type=\"serviceruntime.googleapis.com/api/request_latencies\" resource.type=\"api\" " + range { + max = 0.5 + } + } } } `, context) diff --git a/website/docs/r/monitoring_slo.html.markdown b/website/docs/r/monitoring_slo.html.markdown index ae898a024da..90e11960eec 100644 --- a/website/docs/r/monitoring_slo.html.markdown +++ b/website/docs/r/monitoring_slo.html.markdown @@ -92,16 +92,11 @@ resource "google_monitoring_slo" "request_based_slo" { request_based_sli { distribution_cut { - distribution_filter = join(" AND ", [ - "metric.type=\"serviceruntime.googleapis.com/api/request_latencies\"", - "resource.type=\"consumed_api\"", - "resource.label.\"project_id\"=\"my-project-name\"", - ]) - - range { - max = 10 - } - } + distribution_filter = "metric.type=\"serviceruntime.googleapis.com/api/request_latencies\" resource.type=\"api\" " + range { + max = 0.5 + } + } } } ```