diff --git a/google/resource_logging_metric.go b/google/resource_logging_metric.go index f2c6dbe2447..bf641dc5a06 100644 --- a/google/resource_logging_metric.go +++ b/google/resource_logging_metric.go @@ -85,6 +85,11 @@ func resourceLoggingMetric() *schema.Resource { }, }, }, + "unit": { + Type: schema.TypeString, + Optional: true, + Default: "1", + }, }, }, }, @@ -456,6 +461,8 @@ func flattenLoggingMetricMetricDescriptor(v interface{}, d *schema.ResourceData) return nil } transformed := make(map[string]interface{}) + transformed["unit"] = + flattenLoggingMetricMetricDescriptorUnit(original["unit"], d) transformed["value_type"] = flattenLoggingMetricMetricDescriptorValueType(original["valueType"], d) transformed["metric_kind"] = @@ -464,6 +471,10 @@ func flattenLoggingMetricMetricDescriptor(v interface{}, d *schema.ResourceData) flattenLoggingMetricMetricDescriptorLabels(original["labels"], d) return []interface{}{transformed} } +func flattenLoggingMetricMetricDescriptorUnit(v interface{}, d *schema.ResourceData) interface{} { + return v +} + func flattenLoggingMetricMetricDescriptorValueType(v interface{}, d *schema.ResourceData) interface{} { return v } @@ -652,6 +663,13 @@ func expandLoggingMetricMetricDescriptor(v interface{}, d TerraformResourceData, original := raw.(map[string]interface{}) transformed := make(map[string]interface{}) + transformedUnit, err := expandLoggingMetricMetricDescriptorUnit(original["unit"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUnit); val.IsValid() && !isEmptyValue(val) { + transformed["unit"] = transformedUnit + } + transformedValueType, err := expandLoggingMetricMetricDescriptorValueType(original["value_type"], d, config) if err != nil { return nil, err @@ -676,6 +694,10 @@ func expandLoggingMetricMetricDescriptor(v interface{}, d TerraformResourceData, return transformed, nil } +func expandLoggingMetricMetricDescriptorUnit(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandLoggingMetricMetricDescriptorValueType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } diff --git a/google/resource_logging_metric_generated_test.go b/google/resource_logging_metric_generated_test.go index ca7407138b6..91a2a1b2960 100644 --- a/google/resource_logging_metric_generated_test.go +++ b/google/resource_logging_metric_generated_test.go @@ -56,6 +56,7 @@ resource "google_logging_metric" "logging_metric" { metric_descriptor { metric_kind = "DELTA" value_type = "DISTRIBUTION" + unit = "1" labels { key = "mass" value_type = "STRING" diff --git a/website/docs/r/logging_metric.html.markdown b/website/docs/r/logging_metric.html.markdown index 7942092c421..3a859be939c 100644 --- a/website/docs/r/logging_metric.html.markdown +++ b/website/docs/r/logging_metric.html.markdown @@ -48,6 +48,7 @@ resource "google_logging_metric" "logging_metric" { metric_descriptor { metric_kind = "DELTA" value_type = "DISTRIBUTION" + unit = "1" labels { key = "mass" value_type = "STRING" @@ -133,6 +134,12 @@ The following arguments are supported: The `metric_descriptor` block supports: +* `unit` - + (Optional) + The unit in which the metric value is reported. It is only applicable if the valueType is + `INT64`, `DOUBLE`, or `DISTRIBUTION`. The supported units are a subset of + [The Unified Code for Units of Measure](http://unitsofmeasure.org/ucum.html) standard + * `value_type` - (Required) Whether the measurement is an integer, a floating-point number, etc.