Skip to content

Commit

Permalink
update explicit buckets name and make item_type of bounds float
Browse files Browse the repository at this point in the history
  • Loading branch information
megan07 authored Sep 3, 2019
2 parents 37dc50f + d5e9518 commit e98e87b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
26 changes: 13 additions & 13 deletions google/resource_logging_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -108,7 +108,7 @@ func resourceLoggingMetric() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeFloat,
},
},
},
Expand Down Expand Up @@ -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{} {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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
}
44 changes: 44 additions & 0 deletions google/resource_logging_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions website/docs/r/logging_metric.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e98e87b

Please sign in to comment.