diff --git a/google/resource_logging_metric.go b/google/resource_logging_metric.go index 33e992d2a47..f2c6dbe2447 100644 --- a/google/resource_logging_metric.go +++ b/google/resource_logging_metric.go @@ -98,7 +98,7 @@ func resourceLoggingMetric() *schema.Resource { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "explicit": { + "explicit_buckets": { Type: schema.TypeList, Optional: true, MaxItems: 1, @@ -108,7 +108,7 @@ func resourceLoggingMetric() *schema.Resource { Type: schema.TypeList, Optional: true, Elem: &schema.Schema{ - Type: schema.TypeString, + Type: schema.TypeFloat, }, }, }, @@ -528,8 +528,8 @@ func flattenLoggingMetricBucketOptions(v interface{}, d *schema.ResourceData) in flattenLoggingMetricBucketOptionsLinearBuckets(original["linearBuckets"], d) transformed["exponential_buckets"] = flattenLoggingMetricBucketOptionsExponentialBuckets(original["exponentialBuckets"], d) - transformed["explicit"] = - flattenLoggingMetricBucketOptionsExplicit(original["explicit"], d) + transformed["explicit_buckets"] = + flattenLoggingMetricBucketOptionsExplicitBuckets(original["explicitBuckets"], d) return []interface{}{transformed} } func flattenLoggingMetricBucketOptionsLinearBuckets(v interface{}, d *schema.ResourceData) interface{} { @@ -614,7 +614,7 @@ func flattenLoggingMetricBucketOptionsExponentialBucketsScale(v interface{}, d * return v } -func flattenLoggingMetricBucketOptionsExplicit(v interface{}, d *schema.ResourceData) interface{} { +func flattenLoggingMetricBucketOptionsExplicitBuckets(v interface{}, d *schema.ResourceData) interface{} { if v == nil { return nil } @@ -624,10 +624,10 @@ func flattenLoggingMetricBucketOptionsExplicit(v interface{}, d *schema.Resource } transformed := make(map[string]interface{}) transformed["bounds"] = - flattenLoggingMetricBucketOptionsExplicitBounds(original["bounds"], d) + flattenLoggingMetricBucketOptionsExplicitBucketsBounds(original["bounds"], d) return []interface{}{transformed} } -func flattenLoggingMetricBucketOptionsExplicitBounds(v interface{}, d *schema.ResourceData) interface{} { +func flattenLoggingMetricBucketOptionsExplicitBucketsBounds(v interface{}, d *schema.ResourceData) interface{} { return v } @@ -770,11 +770,11 @@ func expandLoggingMetricBucketOptions(v interface{}, d TerraformResourceData, co transformed["exponentialBuckets"] = transformedExponentialBuckets } - transformedExplicit, err := expandLoggingMetricBucketOptionsExplicit(original["explicit"], d, config) + transformedExplicitBuckets, err := expandLoggingMetricBucketOptionsExplicitBuckets(original["explicit_buckets"], d, config) if err != nil { return nil, err - } else if val := reflect.ValueOf(transformedExplicit); val.IsValid() && !isEmptyValue(val) { - transformed["explicit"] = transformedExplicit + } else if val := reflect.ValueOf(transformedExplicitBuckets); val.IsValid() && !isEmptyValue(val) { + transformed["explicitBuckets"] = transformedExplicitBuckets } return transformed, nil @@ -870,7 +870,7 @@ func expandLoggingMetricBucketOptionsExponentialBucketsScale(v interface{}, d Te return v, nil } -func expandLoggingMetricBucketOptionsExplicit(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { +func expandLoggingMetricBucketOptionsExplicitBuckets(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { return nil, nil @@ -879,7 +879,7 @@ func expandLoggingMetricBucketOptionsExplicit(v interface{}, d TerraformResource original := raw.(map[string]interface{}) transformed := make(map[string]interface{}) - transformedBounds, err := expandLoggingMetricBucketOptionsExplicitBounds(original["bounds"], d, config) + transformedBounds, err := expandLoggingMetricBucketOptionsExplicitBucketsBounds(original["bounds"], d, config) if err != nil { return nil, err } else if val := reflect.ValueOf(transformedBounds); val.IsValid() && !isEmptyValue(val) { @@ -889,6 +889,6 @@ func expandLoggingMetricBucketOptionsExplicit(v interface{}, d TerraformResource return transformed, nil } -func expandLoggingMetricBucketOptionsExplicitBounds(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { +func expandLoggingMetricBucketOptionsExplicitBucketsBounds(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } diff --git a/google/resource_logging_metric_test.go b/google/resource_logging_metric_test.go index f1585e1e955..b8c3c546ef6 100644 --- a/google/resource_logging_metric_test.go +++ b/google/resource_logging_metric_test.go @@ -40,6 +40,29 @@ func TestAccLoggingMetric_update(t *testing.T) { }) } +func TestAccLoggingMetric_explicitBucket(t *testing.T) { + t.Parallel() + + suffix := acctest.RandString(10) + filter := "resource.type=gae_app AND severity>=ERROR" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLoggingMetricDestroy, + Steps: []resource.TestStep{ + { + Config: testAccLoggingMetric_explicitBucket(suffix, filter), + }, + { + 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" { @@ -51,3 +74,24 @@ resource "google_logging_metric" "logging_metric" { } }`, suffix, filter) } + +func testAccLoggingMetric_explicitBucket(suffix string, filter string) string { + return fmt.Sprintf(` +resource "google_logging_metric" "logging_metric" { + name = "my-custom-metric-%s" + filter = "%s" + + metric_descriptor { + metric_kind = "DELTA" + value_type = "DISTRIBUTION" + } + + value_extractor = "EXTRACT(jsonPayload.metrics.running_jobs)" + + bucket_options { + explicit_buckets { + bounds = [0,1,2,3,4.2] + } + } +}`, suffix, filter) +} diff --git a/website/docs/r/logging_metric.html.markdown b/website/docs/r/logging_metric.html.markdown index cfd71a9c076..7942092c421 100644 --- a/website/docs/r/logging_metric.html.markdown +++ b/website/docs/r/logging_metric.html.markdown @@ -213,7 +213,7 @@ The `bucket_options` block supports: Specifies an exponential sequence of buckets that have a width that is proportional to the value of the lower bound. Each bucket represents a constant relative uncertainty on a specific value in the bucket. Structure is documented below. -* `explicit` - +* `explicit_buckets` - (Optional) Specifies a set of buckets with arbitrary widths. Structure is documented below. @@ -246,7 +246,7 @@ The `exponential_buckets` block supports: (Optional) Must be greater than 0. -The `explicit` block supports: +The `explicit_buckets` block supports: * `bounds` - (Optional)