Skip to content

Commit

Permalink
Added ForceNew on labels (#4734) (#9057)
Browse files Browse the repository at this point in the history
* Added ForeNew on labels

* set ForceNew on key & key_value

* added a test

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored May 3, 2021
1 parent fb5f35b commit 32d49b2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/4734.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
logging: fixed `metric_descriptor.labels` can't be updated on 'google_logging_metric'
```
2 changes: 2 additions & 0 deletions google/resource_logging_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func loggingMetricMetricDescriptorLabelsSchema() *schema.Resource {
"key": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The label key.`,
},
"description": {
Expand All @@ -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",
Expand Down
59 changes: 59 additions & 0 deletions google/resource_logging_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}

0 comments on commit 32d49b2

Please sign in to comment.