From 32d49b285cc47badce32cc57213a6c829a6c8659 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 3 May 2021 13:44:07 -0700 Subject: [PATCH] Added ForceNew on labels (#4734) (#9057) * Added ForeNew on labels * set ForceNew on key & key_value * added a test Signed-off-by: Modular Magician --- .changelog/4734.txt | 3 ++ google/resource_logging_metric.go | 2 + google/resource_logging_metric_test.go | 59 ++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 .changelog/4734.txt diff --git a/.changelog/4734.txt b/.changelog/4734.txt new file mode 100644 index 00000000000..875837eb192 --- /dev/null +++ b/.changelog/4734.txt @@ -0,0 +1,3 @@ +```release-note:bug +logging: fixed `metric_descriptor.labels` can't be updated on 'google_logging_metric' +``` diff --git a/google/resource_logging_metric.go b/google/resource_logging_metric.go index e978c3261a6..a2661aee8eb 100644 --- a/google/resource_logging_metric.go +++ b/google/resource_logging_metric.go @@ -242,6 +242,7 @@ func loggingMetricMetricDescriptorLabelsSchema() *schema.Resource { "key": { Type: schema.TypeString, Required: true, + ForceNew: true, Description: `The label key.`, }, "description": { @@ -252,6 +253,7 @@ func loggingMetricMetricDescriptorLabelsSchema() *schema.Resource { "value_type": { Type: schema.TypeString, Optional: true, + ForceNew: true, ValidateFunc: validation.StringInSlice([]string{"BOOL", "INT64", "STRING", ""}, false), Description: `The type of data that can be assigned to the label. Default value: "STRING" Possible values: ["BOOL", "INT64", "STRING"]`, Default: "STRING", diff --git a/google/resource_logging_metric_test.go b/google/resource_logging_metric_test.go index 5555291066c..8281366c5c2 100644 --- a/google/resource_logging_metric_test.go +++ b/google/resource_logging_metric_test.go @@ -62,6 +62,36 @@ func TestAccLoggingMetric_explicitBucket(t *testing.T) { }) } +func TestAccLoggingMetric_descriptionUpdated(t *testing.T) { + t.Parallel() + + suffix := randString(t, 10) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLoggingMetricDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccLoggingMetric_descriptionUpdated(suffix, "original"), + }, + { + ResourceName: "google_logging_metric.logging_metric", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccLoggingMetric_descriptionUpdated(suffix, "Updated"), + }, + { + ResourceName: "google_logging_metric.logging_metric", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccLoggingMetric_update(suffix string, filter string) string { return fmt.Sprintf(` resource "google_logging_metric" "logging_metric" { @@ -97,3 +127,32 @@ resource "google_logging_metric" "logging_metric" { } `, suffix, filter) } + +func testAccLoggingMetric_descriptionUpdated(suffix, description string) string { + return fmt.Sprintf(` +resource "google_logging_metric" "logging_metric" { + name = "my-custom-metric-%s" + description = "Counter for VM instances that have hostError's" + filter = "resource.type=gce_instance AND protoPayload.methodName=compute.instances.hostError" + metric_descriptor { + metric_kind = "DELTA" + value_type = "INT64" + labels { + key = "instance" + value_type = "STRING" + description = "%s" + } + labels { + key = "zone" + value_type = "STRING" + description = "Availability zone of instance" + } + display_name = "VM Host Errors" + } + label_extractors = { + "instance" = "REGEXP_EXTRACT(protoPayload.resourceName, \"projects/.+/zones/.+/instances/(.+)\")" + "zone" = "EXTRACT(resource.labels.zone)" + } + } +`, suffix, description) +}