From 3cbed43011db2f12834bc35703c8474b3264e555 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Mon, 21 Dec 2020 16:58:28 -0800 Subject: [PATCH 1/9] inital check-in for review --- products/monitoring/api.yaml | 16 ++++++- products/monitoring/terraform.yaml | 2 + .../monitoring_slo_availability_sli.go.erb | 22 ++++++++++ .../tests/resource_monitoring_slo_test.go | 42 +++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb diff --git a/products/monitoring/api.yaml b/products/monitoring/api.yaml index 28ccc97d23b0..25bc244e3186 100644 --- a/products/monitoring/api.yaml +++ b/products/monitoring/api.yaml @@ -1144,7 +1144,9 @@ objects: name: latency description: | Parameters for a latency threshold SLI. - required: true + exactly_one_of: + - service_level_indicator.0.basic_sli.0.latency + - service_level_indicator.0.basic_sli.0.availability properties: - !ruby/object:Api::Type::String required: true @@ -1153,6 +1155,18 @@ objects: A duration string, e.g. 10s. Good service is defined to be the count of requests made to this service that return in no more than threshold. + - !ruby/object:Api::Type::NestedObject + name: availability + description: | + Availability based SLI, dervied from count of requests made to this service that return successfully. + exactly_one_of: + - service_level_indicator.0.basic_sli.0.latency + - service_level_indicator.0.basic_sli.0.availability + properties: + - !ruby/object:Api::Type::String + name: forFuture + description: | + Place holder - !ruby/object:Api::Type::NestedObject name: requestBasedSli api_name: 'requestBased' diff --git a/products/monitoring/terraform.yaml b/products/monitoring/terraform.yaml index 6592a7de66e6..b78280cd69d5 100644 --- a/products/monitoring/terraform.yaml +++ b/products/monitoring/terraform.yaml @@ -194,6 +194,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides is_set: true serviceLevelIndicator.basicSli.version: !ruby/object:Overrides::Terraform::PropertyOverride is_set: true + serviceLevelIndicator.basicSli.availability: !ruby/object:Overrides::Terraform::PropertyOverride + custom_expand: 'templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb' serviceLevelIndicator.requestBasedSli: !ruby/object:Overrides::Terraform::PropertyOverride # Force update all nested fields to allow for unsetting values. update_mask_fields: diff --git a/templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb b/templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb new file mode 100644 index 000000000000..58a96297db25 --- /dev/null +++ b/templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb @@ -0,0 +1,22 @@ +<%- # the license inside this block applies to this file + # Copyright 2020 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 expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 { + return nil, nil + } + + return struct{}{}, nil +} diff --git a/third_party/terraform/tests/resource_monitoring_slo_test.go b/third_party/terraform/tests/resource_monitoring_slo_test.go index 74180cecb29e..5c82ff049a5d 100644 --- a/third_party/terraform/tests/resource_monitoring_slo_test.go +++ b/third_party/terraform/tests/resource_monitoring_slo_test.go @@ -104,6 +104,29 @@ func TestAccMonitoringSlo_basic(t *testing.T) { }) } +func TestAccMonitoringSlo_availabilitySli(t *testing.T) { + t.Parallel() + + var generatedId string + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMonitoringSloDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccMonitoringSlo_availabilitySli(), + Check: setTestCheckMonitoringSloId("google_monitoring_slo.primary", &generatedId), + }, + { + ResourceName: "google_monitoring_slo.primary", + ImportState: true, + ImportStateVerify: true, + // Ignore input-only field for import + ImportStateVerifyIgnore: []string{"service"}, + }, + }, + }) +} func TestAccMonitoringSlo_requestBased(t *testing.T) { t.Parallel() @@ -409,6 +432,25 @@ resource "google_monitoring_slo" "primary" { ` } +func testAccMonitoringSlo_availabilitySli() string { + return ` +data "google_monitoring_app_engine_service" "ae" { + module_id = "default" +} + +resource "google_monitoring_slo" "primary" { + service = data.google_monitoring_app_engine_service.ae.service_id + + goal = 0.9 + rolling_period_days = 1 + + basic_sli { + availability { + } + } +} +` +} func testAccMonitoringSloForSli(randSuffix, sliConfig string) string { return fmt.Sprintf(` resource "google_monitoring_custom_service" "srv" { From 4eb7e107dafde1cdadfa339412ca590e5e07f392 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Tue, 29 Dec 2020 13:34:12 -0800 Subject: [PATCH 2/9] custom_flattner added --- products/monitoring/api.yaml | 7 ++-- products/monitoring/terraform.yaml | 3 +- .../monitoring_slo_availability_sli.go.erb | 33 +++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb diff --git a/products/monitoring/api.yaml b/products/monitoring/api.yaml index 25bc244e3186..f87e6d904304 100644 --- a/products/monitoring/api.yaml +++ b/products/monitoring/api.yaml @@ -1163,10 +1163,11 @@ objects: - service_level_indicator.0.basic_sli.0.latency - service_level_indicator.0.basic_sli.0.availability properties: - - !ruby/object:Api::Type::String - name: forFuture + - !ruby/object:Api::Type::Boolean + name: enabled + default_value: true description: | - Place holder + Enable availability sli - !ruby/object:Api::Type::NestedObject name: requestBasedSli api_name: 'requestBased' diff --git a/products/monitoring/terraform.yaml b/products/monitoring/terraform.yaml index b78280cd69d5..5307714285b6 100644 --- a/products/monitoring/terraform.yaml +++ b/products/monitoring/terraform.yaml @@ -195,7 +195,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides serviceLevelIndicator.basicSli.version: !ruby/object:Overrides::Terraform::PropertyOverride is_set: true serviceLevelIndicator.basicSli.availability: !ruby/object:Overrides::Terraform::PropertyOverride - custom_expand: 'templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb' + custom_expand: 'templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb' + custom_flatten: 'templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb' serviceLevelIndicator.requestBasedSli: !ruby/object:Overrides::Terraform::PropertyOverride # Force update all nested fields to allow for unsetting values. update_mask_fields: diff --git a/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb b/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb new file mode 100644 index 000000000000..0393988d5838 --- /dev/null +++ b/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb @@ -0,0 +1,33 @@ +<%# The license inside this block applies to this file. + # Copyright 2020 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["enabled"] = + flattenMonitoringSloServiceLevelIndicatorBasicSliAvailabilityEnabled(original["enabled"], d, config) + return []interface{}{transformed} +} + + +func flattenMonitoringSloServiceLevelIndicatorBasicSliAvailabilityEnabled(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil || isEmptyValue(reflect.ValueOf(v)) { + return true + } + + return v +} \ No newline at end of file From f62743a237767f13dcc1a10e150e123717ff4de3 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Tue, 29 Dec 2020 13:38:56 -0800 Subject: [PATCH 3/9] extra line added at EOF --- .../custom_flatten/monitoring_slo_availability_sli.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb b/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb index 0393988d5838..ebee376b982d 100644 --- a/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb +++ b/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb @@ -30,4 +30,4 @@ func flattenMonitoringSloServiceLevelIndicatorBasicSliAvailabilityEnabled(v inte } return v -} \ No newline at end of file +} From 0d1a1665b3944e677d3354df5c760a62c08482ff Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Mon, 4 Jan 2021 18:22:01 -0800 Subject: [PATCH 4/9] PR comments implemented --- products/monitoring/api.yaml | 2 +- .../monitoring_slo_availability_sli.go.erb | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/products/monitoring/api.yaml b/products/monitoring/api.yaml index f87e6d904304..8086dff279cf 100644 --- a/products/monitoring/api.yaml +++ b/products/monitoring/api.yaml @@ -1167,7 +1167,7 @@ objects: name: enabled default_value: true description: | - Enable availability sli + Whether an availability SLI is enabled or not. Defaults to `true`. - !ruby/object:Api::Type::NestedObject name: requestBasedSli api_name: 'requestBased' diff --git a/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb b/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb index ebee376b982d..b899b35b120b 100644 --- a/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb +++ b/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb @@ -16,18 +16,7 @@ func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d if v == nil { return nil } - original := v.(map[string]interface{}) transformed := make(map[string]interface{}) - transformed["enabled"] = - flattenMonitoringSloServiceLevelIndicatorBasicSliAvailabilityEnabled(original["enabled"], d, config) + transformed["enabled"] = true return []interface{}{transformed} } - - -func flattenMonitoringSloServiceLevelIndicatorBasicSliAvailabilityEnabled(v interface{}, d *schema.ResourceData, config *Config) interface{} { - if v == nil || isEmptyValue(reflect.ValueOf(v)) { - return true - } - - return v -} From 0f9306e597b94fcec26009739caea7a463260ae5 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Fri, 8 Jan 2021 15:51:27 -0800 Subject: [PATCH 5/9] custom_expander logic is placed in encoder as it more appropriate, validation func added --- products/monitoring/terraform.yaml | 4 +++- .../terraform/constants/monitoring_slo.go.erb | 7 ++++++ .../monitoring_slo_availability_sli.go.erb | 22 ------------------- .../terraform/encoders/monitoring_slo.go.erb | 9 ++++++++ 4 files changed, 19 insertions(+), 23 deletions(-) delete mode 100644 templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb diff --git a/products/monitoring/terraform.yaml b/products/monitoring/terraform.yaml index 5307714285b6..6f1108cfd8fa 100644 --- a/products/monitoring/terraform.yaml +++ b/products/monitoring/terraform.yaml @@ -195,8 +195,10 @@ overrides: !ruby/object:Overrides::ResourceOverrides serviceLevelIndicator.basicSli.version: !ruby/object:Overrides::Terraform::PropertyOverride is_set: true serviceLevelIndicator.basicSli.availability: !ruby/object:Overrides::Terraform::PropertyOverride - custom_expand: 'templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb' custom_flatten: 'templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb' + serviceLevelIndicator.basicSli.availability.enabled: !ruby/object:Overrides::Terraform::PropertyOverride + validation: !ruby/object:Provider::Terraform::Validation + function: validateAvailabilitySli serviceLevelIndicator.requestBasedSli: !ruby/object:Overrides::Terraform::PropertyOverride # Force update all nested fields to allow for unsetting values. update_mask_fields: diff --git a/templates/terraform/constants/monitoring_slo.go.erb b/templates/terraform/constants/monitoring_slo.go.erb index 23b42305d7ae..9959e1a8e1e0 100644 --- a/templates/terraform/constants/monitoring_slo.go.erb +++ b/templates/terraform/constants/monitoring_slo.go.erb @@ -4,4 +4,11 @@ func validateMonitoringSloGoal(v interface{}, k string) (warnings []string, erro errors = append(errors, fmt.Errorf("goal %f must be > 0 and <= 0.999", goal)) } return +} + +func validateAvailabilitySli(v interface{}, key string) (ws []string, errs []error) { + if v.(bool) == false { + errs = append(errs, fmt.Errorf("%q must be set to true, got: %v", key, v)) + } + return } \ No newline at end of file diff --git a/templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb b/templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb deleted file mode 100644 index 58a96297db25..000000000000 --- a/templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb +++ /dev/null @@ -1,22 +0,0 @@ -<%- # the license inside this block applies to this file - # Copyright 2020 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 expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - l := v.([]interface{}) - if len(l) == 0 { - return nil, nil - } - - return struct{}{}, nil -} diff --git a/templates/terraform/encoders/monitoring_slo.go.erb b/templates/terraform/encoders/monitoring_slo.go.erb index 6a8a950629a4..00cc9f257270 100644 --- a/templates/terraform/encoders/monitoring_slo.go.erb +++ b/templates/terraform/encoders/monitoring_slo.go.erb @@ -15,4 +15,13 @@ // Name/Service Level Objective ID is a query parameter and cannot // be given in data delete(obj, "sloId") +basSli := obj["serviceLevelIndicator"].(map[string]interface{})["basicSli"].(map[string]interface{}) + +//Removing the dummy attribute + if availability, ok := basSli["availability"]; ok { + transAvailability := availability.(map[string]interface{}) + delete(transAvailability, "enabled") + basSli["availability"] = transAvailability + } + return obj, nil \ No newline at end of file From 097fdafbb4c8cdea50b4eb6b996abb006145e16a Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Fri, 8 Jan 2021 15:55:36 -0800 Subject: [PATCH 6/9] empty lines added at EOF --- templates/terraform/constants/monitoring_slo.go.erb | 2 +- templates/terraform/encoders/monitoring_slo.go.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/terraform/constants/monitoring_slo.go.erb b/templates/terraform/constants/monitoring_slo.go.erb index 9959e1a8e1e0..f905eaec9ad1 100644 --- a/templates/terraform/constants/monitoring_slo.go.erb +++ b/templates/terraform/constants/monitoring_slo.go.erb @@ -11,4 +11,4 @@ func validateAvailabilitySli(v interface{}, key string) (ws []string, errs []err errs = append(errs, fmt.Errorf("%q must be set to true, got: %v", key, v)) } return -} \ No newline at end of file +} diff --git a/templates/terraform/encoders/monitoring_slo.go.erb b/templates/terraform/encoders/monitoring_slo.go.erb index 00cc9f257270..b285facc5836 100644 --- a/templates/terraform/encoders/monitoring_slo.go.erb +++ b/templates/terraform/encoders/monitoring_slo.go.erb @@ -24,4 +24,4 @@ basSli := obj["serviceLevelIndicator"].(map[string]interface{})["basicSli"].(map basSli["availability"] = transAvailability } -return obj, nil \ No newline at end of file +return obj, nil From 60112f4ff61519c4075ce427cc7dbae0217fa313 Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Thu, 14 Jan 2021 11:28:29 -0800 Subject: [PATCH 7/9] PR comments implemented, Test cases added --- products/monitoring/api.yaml | 2 +- .../monitoring_slo_availability_sli.go.erb | 2 +- templates/terraform/encoders/monitoring_slo.go.erb | 4 ++-- .../terraform/tests/resource_monitoring_slo_test.go | 12 ++++++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/products/monitoring/api.yaml b/products/monitoring/api.yaml index 8086dff279cf..52ef54330d58 100644 --- a/products/monitoring/api.yaml +++ b/products/monitoring/api.yaml @@ -1167,7 +1167,7 @@ objects: name: enabled default_value: true description: | - Whether an availability SLI is enabled or not. Defaults to `true`. + Whether an availability SLI is enabled or not. Must be set to `true. Defaults to `true`. - !ruby/object:Api::Type::NestedObject name: requestBasedSli api_name: 'requestBased' diff --git a/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb b/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb index b899b35b120b..89f56f6bba70 100644 --- a/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb +++ b/templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb @@ -13,7 +13,7 @@ # limitations under the License. -%> func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { - if v == nil { + if v == nil { return nil } transformed := make(map[string]interface{}) diff --git a/templates/terraform/encoders/monitoring_slo.go.erb b/templates/terraform/encoders/monitoring_slo.go.erb index b285facc5836..53f255432e16 100644 --- a/templates/terraform/encoders/monitoring_slo.go.erb +++ b/templates/terraform/encoders/monitoring_slo.go.erb @@ -17,11 +17,11 @@ delete(obj, "sloId") basSli := obj["serviceLevelIndicator"].(map[string]interface{})["basicSli"].(map[string]interface{}) -//Removing the dummy attribute +//Removing the dummy `enabled` attribute if availability, ok := basSli["availability"]; ok { transAvailability := availability.(map[string]interface{}) delete(transAvailability, "enabled") basSli["availability"] = transAvailability } - return obj, nil + diff --git a/third_party/terraform/tests/resource_monitoring_slo_test.go b/third_party/terraform/tests/resource_monitoring_slo_test.go index 5c82ff049a5d..281381a478d3 100644 --- a/third_party/terraform/tests/resource_monitoring_slo_test.go +++ b/third_party/terraform/tests/resource_monitoring_slo_test.go @@ -124,6 +124,17 @@ func TestAccMonitoringSlo_availabilitySli(t *testing.T) { // Ignore input-only field for import ImportStateVerifyIgnore: []string{"service"}, }, + { + Config: testAccMonitoringSlo_basicUpdate(), + Check: testCheckMonitoringSloIdAfterUpdate("google_monitoring_slo.primary", &generatedId), + }, + { + ResourceName: "google_monitoring_slo.primary", + ImportState: true, + ImportStateVerify: true, + // Ignore input-only field for import + ImportStateVerifyIgnore: []string{"service"}, + }, }, }) } @@ -451,6 +462,7 @@ resource "google_monitoring_slo" "primary" { } ` } + func testAccMonitoringSloForSli(randSuffix, sliConfig string) string { return fmt.Sprintf(` resource "google_monitoring_custom_service" "srv" { From 38de1fccab001467d4f0c60043568e4ec8f21aea Mon Sep 17 00:00:00 2001 From: venkykuberan Date: Tue, 19 Jan 2021 16:00:22 -0800 Subject: [PATCH 8/9] fixed encoder for the case where basicsli is not used in the config --- templates/terraform/encoders/monitoring_slo.go.erb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/templates/terraform/encoders/monitoring_slo.go.erb b/templates/terraform/encoders/monitoring_slo.go.erb index 53f255432e16..c330cc5503ab 100644 --- a/templates/terraform/encoders/monitoring_slo.go.erb +++ b/templates/terraform/encoders/monitoring_slo.go.erb @@ -15,13 +15,14 @@ // Name/Service Level Objective ID is a query parameter and cannot // be given in data delete(obj, "sloId") -basSli := obj["serviceLevelIndicator"].(map[string]interface{})["basicSli"].(map[string]interface{}) - -//Removing the dummy `enabled` attribute - if availability, ok := basSli["availability"]; ok { +Sli := obj["serviceLevelIndicator"].(map[string]interface{}) +if basicSli, ok := Sli["basicSli"].(map[string]interface{}); ok { + //Removing the dummy `enabled` attribute + if availability, ok := basicSli["availability"]; ok { transAvailability := availability.(map[string]interface{}) delete(transAvailability, "enabled") - basSli["availability"] = transAvailability + basicSli["availability"] = transAvailability } +} return obj, nil From 901f4fd704050f5326841f82f3e606b96c4d9b7d Mon Sep 17 00:00:00 2001 From: venky kuberan Date: Sun, 28 Feb 2021 22:58:54 -0800 Subject: [PATCH 9/9] windows based availability sli support added --- mmv1/products/monitoring/api.yaml | 19 +++++++++-- mmv1/products/monitoring/terraform.yaml | 5 +++ .../terraform/encoders/monitoring_slo.go.erb | 14 ++++++++ .../tests/resource_monitoring_slo_test.go | 33 +++++++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/mmv1/products/monitoring/api.yaml b/mmv1/products/monitoring/api.yaml index cd390cda97ee..39f3b347a80b 100644 --- a/mmv1/products/monitoring/api.yaml +++ b/mmv1/products/monitoring/api.yaml @@ -1168,7 +1168,7 @@ objects: name: enabled default_value: true description: | - Whether an availability SLI is enabled or not. Must be set to `true. Defaults to `true`. + Whether an availability SLI is enabled or not. Must be set to true. Defaults to `true`. - !ruby/object:Api::Type::NestedObject name: requestBasedSli api_name: 'requestBased' @@ -1511,9 +1511,11 @@ objects: item_type: Api::Type::String - !ruby/object:Api::Type::NestedObject name: latency - required: true description: | Parameters for a latency threshold SLI. + exactly_one_of: + - service_level_indicator.0.windows_based_sli.0.good_total_ratio_threshold.0.basic_sli_performance.0.latency + - service_level_indicator.0.windows_based_sli.0.good_total_ratio_threshold.0.basic_sli_performance.0.availability properties: - !ruby/object:Api::Type::String required: true @@ -1522,6 +1524,19 @@ objects: A duration string, e.g. 10s. Good service is defined to be the count of requests made to this service that return in no more than threshold. + - !ruby/object:Api::Type::NestedObject + name: availability + description: | + Availability based SLI, dervied from count of requests made to this service that return successfully. + exactly_one_of: + - service_level_indicator.0.windows_based_sli.0.good_total_ratio_threshold.0.basic_sli_performance.0.latency + - service_level_indicator.0.windows_based_sli.0.good_total_ratio_threshold.0.basic_sli_performance.0.availability + properties: + - !ruby/object:Api::Type::Boolean + name: enabled + default_value: true + description: | + Whether an availability SLI is enabled or not. Must be set to `true. Defaults to `true`. - !ruby/object:Api::Type::NestedObject name: metricMeanInRange exactly_one_of: diff --git a/mmv1/products/monitoring/terraform.yaml b/mmv1/products/monitoring/terraform.yaml index 6f1108cfd8fa..a2a75c2a6ee8 100644 --- a/mmv1/products/monitoring/terraform.yaml +++ b/mmv1/products/monitoring/terraform.yaml @@ -199,6 +199,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides serviceLevelIndicator.basicSli.availability.enabled: !ruby/object:Overrides::Terraform::PropertyOverride validation: !ruby/object:Provider::Terraform::Validation function: validateAvailabilitySli + serviceLevelIndicator.windowsBasedSli.goodTotalRatioThreshold.basicSliPerformance.availability: !ruby/object:Overrides::Terraform::PropertyOverride + custom_flatten: 'templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb' + serviceLevelIndicator.windowsBasedSli.goodTotalRatioThreshold.basicSliPerformance.availability.enabled: !ruby/object:Overrides::Terraform::PropertyOverride + validation: !ruby/object:Provider::Terraform::Validation + function: validateAvailabilitySli serviceLevelIndicator.requestBasedSli: !ruby/object:Overrides::Terraform::PropertyOverride # Force update all nested fields to allow for unsetting values. update_mask_fields: diff --git a/mmv1/templates/terraform/encoders/monitoring_slo.go.erb b/mmv1/templates/terraform/encoders/monitoring_slo.go.erb index c330cc5503ab..5f5b99f900ed 100644 --- a/mmv1/templates/terraform/encoders/monitoring_slo.go.erb +++ b/mmv1/templates/terraform/encoders/monitoring_slo.go.erb @@ -24,5 +24,19 @@ if basicSli, ok := Sli["basicSli"].(map[string]interface{}); ok { basicSli["availability"] = transAvailability } } + +if windowBasedSli, ok := Sli["windowsBased"].(map[string]interface{}); ok { + if goodTotalRatioThreshold, ok := windowBasedSli["goodTotalRatioThreshold"].(map[string]interface{}); ok { + if basicSli, ok := goodTotalRatioThreshold["basicSliPerformance"].(map[string]interface{}); ok { + //Removing the dummy `enabled` attribute + if availability, ok := basicSli["availability"]; ok { + transAvailability := availability.(map[string]interface{}) + delete(transAvailability, "enabled") + basicSli["availability"] = transAvailability + } + } + } +} + return obj, nil diff --git a/mmv1/third_party/terraform/tests/resource_monitoring_slo_test.go b/mmv1/third_party/terraform/tests/resource_monitoring_slo_test.go index 281381a478d3..bfcc6285064d 100644 --- a/mmv1/third_party/terraform/tests/resource_monitoring_slo_test.go +++ b/mmv1/third_party/terraform/tests/resource_monitoring_slo_test.go @@ -316,6 +316,16 @@ func TestAccMonitoringSlo_windowBasedGoodTotalRatioThresholdSlis(t *testing.T) { // Ignore input-only field for import ImportStateVerifyIgnore: []string{"service"}, }, + { + Config: testAccMonitoringSloSli_windowBasedSliGoodTotalRatioThreshold_basicSli(), + }, + { + ResourceName: "google_monitoring_slo.test_slo", + ImportState: true, + ImportStateVerify: true, + // Ignore input-only field for import + ImportStateVerifyIgnore: []string{"service"}, + }, }, }) } @@ -718,3 +728,26 @@ windows_based_sli { } ` } + +func testAccMonitoringSloSli_windowBasedSliGoodTotalRatioThreshold_basicSli() string { + return fmt.Sprintf(` +data "google_monitoring_app_engine_service" "ae" { + module_id = "default" +} + +resource "google_monitoring_slo" "test_slo" { + service = data.google_monitoring_app_engine_service.ae.service_id + goal = 0.9 + rolling_period_days = 30 + windows_based_sli { + window_period = "400s" + good_total_ratio_threshold { + threshold = 0.1 + basic_sli_performance { + availability { + } + } + } + } +}`) +}