Skip to content

Commit

Permalink
Add metric descriptor unit to google_logging_metric
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
megan07 authored and modular-magician committed Sep 6, 2019
1 parent 2bfcf06 commit 0618c42
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions google/resource_logging_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func resourceLoggingMetric() *schema.Resource {
},
},
},
"unit": {
Type: schema.TypeString,
Optional: true,
Default: "1",
},
},
},
},
Expand Down Expand Up @@ -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"] =
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions google/resource_logging_metric_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/logging_metric.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0618c42

Please sign in to comment.