mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 09:36:44 +00:00
880 lines
29 KiB
Go
880 lines
29 KiB
Go
![]() |
// ----------------------------------------------------------------------------
|
||
|
//
|
||
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||
|
//
|
||
|
// ----------------------------------------------------------------------------
|
||
|
//
|
||
|
// This file is automatically generated by Magic Modules and manual
|
||
|
// changes will be clobbered when the file is regenerated.
|
||
|
//
|
||
|
// Please read more about how to change this file in
|
||
|
// .github/CONTRIBUTING.md.
|
||
|
//
|
||
|
// ----------------------------------------------------------------------------
|
||
|
|
||
|
package google
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"reflect"
|
||
|
"strconv"
|
||
|
"time"
|
||
|
|
||
|
"github.com/hashicorp/terraform/helper/schema"
|
||
|
"github.com/hashicorp/terraform/helper/validation"
|
||
|
)
|
||
|
|
||
|
func resourceLoggingMetric() *schema.Resource {
|
||
|
return &schema.Resource{
|
||
|
Create: resourceLoggingMetricCreate,
|
||
|
Read: resourceLoggingMetricRead,
|
||
|
Update: resourceLoggingMetricUpdate,
|
||
|
Delete: resourceLoggingMetricDelete,
|
||
|
|
||
|
Importer: &schema.ResourceImporter{
|
||
|
State: resourceLoggingMetricImport,
|
||
|
},
|
||
|
|
||
|
Timeouts: &schema.ResourceTimeout{
|
||
|
Create: schema.DefaultTimeout(240 * time.Second),
|
||
|
Update: schema.DefaultTimeout(240 * time.Second),
|
||
|
Delete: schema.DefaultTimeout(240 * time.Second),
|
||
|
},
|
||
|
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"filter": {
|
||
|
Type: schema.TypeString,
|
||
|
Required: true,
|
||
|
},
|
||
|
"metric_descriptor": {
|
||
|
Type: schema.TypeList,
|
||
|
Required: true,
|
||
|
MaxItems: 1,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"metric_kind": {
|
||
|
Type: schema.TypeString,
|
||
|
Required: true,
|
||
|
ValidateFunc: validation.StringInSlice([]string{"DELTA", "GAUGE", "CUMULATIVE"}, false),
|
||
|
},
|
||
|
"value_type": {
|
||
|
Type: schema.TypeString,
|
||
|
Required: true,
|
||
|
ValidateFunc: validation.StringInSlice([]string{"BOOL", "INT64", "DOUBLE", "STRING", "DISTRIBUTION", "MONEY"}, false),
|
||
|
},
|
||
|
"labels": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"key": {
|
||
|
Type: schema.TypeString,
|
||
|
Required: true,
|
||
|
},
|
||
|
"description": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"value_type": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
ValidateFunc: validation.StringInSlice([]string{"BOOL", "INT64", "STRING", ""}, false),
|
||
|
Default: "STRING",
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
"name": {
|
||
|
Type: schema.TypeString,
|
||
|
Required: true,
|
||
|
},
|
||
|
"bucket_options": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
MaxItems: 1,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"explicit": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
MaxItems: 1,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"bounds": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
Elem: &schema.Schema{
|
||
|
Type: schema.TypeString,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
"exponential_buckets": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
MaxItems: 1,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"growth_factor": {
|
||
|
Type: schema.TypeInt,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"num_finite_buckets": {
|
||
|
Type: schema.TypeInt,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"scale": {
|
||
|
Type: schema.TypeFloat,
|
||
|
Optional: true,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
"linear_buckets": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
MaxItems: 1,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"num_finite_buckets": {
|
||
|
Type: schema.TypeInt,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"offset": {
|
||
|
Type: schema.TypeFloat,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"width": {
|
||
|
Type: schema.TypeInt,
|
||
|
Optional: true,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
"description": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"label_extractors": {
|
||
|
Type: schema.TypeMap,
|
||
|
Optional: true,
|
||
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||
|
},
|
||
|
"value_extractor": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"project": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
Computed: true,
|
||
|
ForceNew: true,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func resourceLoggingMetricCreate(d *schema.ResourceData, meta interface{}) error {
|
||
|
config := meta.(*Config)
|
||
|
|
||
|
obj := make(map[string]interface{})
|
||
|
nameProp, err := expandLoggingMetricName(d.Get("name"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
|
||
|
obj["name"] = nameProp
|
||
|
}
|
||
|
descriptionProp, err := expandLoggingMetricDescription(d.Get("description"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
|
||
|
obj["description"] = descriptionProp
|
||
|
}
|
||
|
filterProp, err := expandLoggingMetricFilter(d.Get("filter"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("filter"); !isEmptyValue(reflect.ValueOf(filterProp)) && (ok || !reflect.DeepEqual(v, filterProp)) {
|
||
|
obj["filter"] = filterProp
|
||
|
}
|
||
|
metricDescriptorProp, err := expandLoggingMetricMetricDescriptor(d.Get("metric_descriptor"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("metric_descriptor"); !isEmptyValue(reflect.ValueOf(metricDescriptorProp)) && (ok || !reflect.DeepEqual(v, metricDescriptorProp)) {
|
||
|
obj["metricDescriptor"] = metricDescriptorProp
|
||
|
}
|
||
|
labelExtractorsProp, err := expandLoggingMetricLabelExtractors(d.Get("label_extractors"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("label_extractors"); !isEmptyValue(reflect.ValueOf(labelExtractorsProp)) && (ok || !reflect.DeepEqual(v, labelExtractorsProp)) {
|
||
|
obj["labelExtractors"] = labelExtractorsProp
|
||
|
}
|
||
|
valueExtractorProp, err := expandLoggingMetricValueExtractor(d.Get("value_extractor"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("value_extractor"); !isEmptyValue(reflect.ValueOf(valueExtractorProp)) && (ok || !reflect.DeepEqual(v, valueExtractorProp)) {
|
||
|
obj["valueExtractor"] = valueExtractorProp
|
||
|
}
|
||
|
bucketOptionsProp, err := expandLoggingMetricBucketOptions(d.Get("bucket_options"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("bucket_options"); !isEmptyValue(reflect.ValueOf(bucketOptionsProp)) && (ok || !reflect.DeepEqual(v, bucketOptionsProp)) {
|
||
|
obj["bucketOptions"] = bucketOptionsProp
|
||
|
}
|
||
|
|
||
|
lockName, err := replaceVars(d, config, "customMetric/{{project}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
mutexKV.Lock(lockName)
|
||
|
defer mutexKV.Unlock(lockName)
|
||
|
|
||
|
url, err := replaceVars(d, config, "https://logging.googleapis.com/v2/projects/{{project}}/metrics")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
log.Printf("[DEBUG] Creating new Metric: %#v", obj)
|
||
|
res, err := sendRequestWithTimeout(config, "POST", url, obj, d.Timeout(schema.TimeoutCreate))
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("Error creating Metric: %s", err)
|
||
|
}
|
||
|
|
||
|
// Store the ID now
|
||
|
id, err := replaceVars(d, config, "{{name}}")
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("Error constructing id: %s", err)
|
||
|
}
|
||
|
d.SetId(id)
|
||
|
|
||
|
log.Printf("[DEBUG] Finished creating Metric %q: %#v", d.Id(), res)
|
||
|
|
||
|
// `name` is autogenerated from the api so needs to be set post-create
|
||
|
name, ok := res["name"]
|
||
|
if !ok {
|
||
|
return fmt.Errorf("Create response didn't contain critical fields. Create may not have succeeded.")
|
||
|
}
|
||
|
d.Set("name", name.(string))
|
||
|
d.SetId(name.(string))
|
||
|
|
||
|
return resourceLoggingMetricRead(d, meta)
|
||
|
}
|
||
|
|
||
|
func resourceLoggingMetricRead(d *schema.ResourceData, meta interface{}) error {
|
||
|
config := meta.(*Config)
|
||
|
|
||
|
url, err := replaceVars(d, config, "https://logging.googleapis.com/v2/projects/{{project}}/metrics/{{%name}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
res, err := sendRequest(config, "GET", url, nil)
|
||
|
if err != nil {
|
||
|
return handleNotFoundError(err, d, fmt.Sprintf("LoggingMetric %q", d.Id()))
|
||
|
}
|
||
|
|
||
|
project, err := getProject(d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
if err := d.Set("project", project); err != nil {
|
||
|
return fmt.Errorf("Error reading Metric: %s", err)
|
||
|
}
|
||
|
|
||
|
if err := d.Set("name", flattenLoggingMetricName(res["name"], d)); err != nil {
|
||
|
return fmt.Errorf("Error reading Metric: %s", err)
|
||
|
}
|
||
|
if err := d.Set("description", flattenLoggingMetricDescription(res["description"], d)); err != nil {
|
||
|
return fmt.Errorf("Error reading Metric: %s", err)
|
||
|
}
|
||
|
if err := d.Set("filter", flattenLoggingMetricFilter(res["filter"], d)); err != nil {
|
||
|
return fmt.Errorf("Error reading Metric: %s", err)
|
||
|
}
|
||
|
if err := d.Set("metric_descriptor", flattenLoggingMetricMetricDescriptor(res["metricDescriptor"], d)); err != nil {
|
||
|
return fmt.Errorf("Error reading Metric: %s", err)
|
||
|
}
|
||
|
if err := d.Set("label_extractors", flattenLoggingMetricLabelExtractors(res["labelExtractors"], d)); err != nil {
|
||
|
return fmt.Errorf("Error reading Metric: %s", err)
|
||
|
}
|
||
|
if err := d.Set("value_extractor", flattenLoggingMetricValueExtractor(res["valueExtractor"], d)); err != nil {
|
||
|
return fmt.Errorf("Error reading Metric: %s", err)
|
||
|
}
|
||
|
if err := d.Set("bucket_options", flattenLoggingMetricBucketOptions(res["bucketOptions"], d)); err != nil {
|
||
|
return fmt.Errorf("Error reading Metric: %s", err)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func resourceLoggingMetricUpdate(d *schema.ResourceData, meta interface{}) error {
|
||
|
config := meta.(*Config)
|
||
|
|
||
|
obj := make(map[string]interface{})
|
||
|
nameProp, err := expandLoggingMetricName(d.Get("name"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
|
||
|
obj["name"] = nameProp
|
||
|
}
|
||
|
descriptionProp, err := expandLoggingMetricDescription(d.Get("description"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
|
||
|
obj["description"] = descriptionProp
|
||
|
}
|
||
|
filterProp, err := expandLoggingMetricFilter(d.Get("filter"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("filter"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, filterProp)) {
|
||
|
obj["filter"] = filterProp
|
||
|
}
|
||
|
metricDescriptorProp, err := expandLoggingMetricMetricDescriptor(d.Get("metric_descriptor"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("metric_descriptor"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, metricDescriptorProp)) {
|
||
|
obj["metricDescriptor"] = metricDescriptorProp
|
||
|
}
|
||
|
labelExtractorsProp, err := expandLoggingMetricLabelExtractors(d.Get("label_extractors"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("label_extractors"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelExtractorsProp)) {
|
||
|
obj["labelExtractors"] = labelExtractorsProp
|
||
|
}
|
||
|
valueExtractorProp, err := expandLoggingMetricValueExtractor(d.Get("value_extractor"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("value_extractor"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, valueExtractorProp)) {
|
||
|
obj["valueExtractor"] = valueExtractorProp
|
||
|
}
|
||
|
bucketOptionsProp, err := expandLoggingMetricBucketOptions(d.Get("bucket_options"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("bucket_options"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, bucketOptionsProp)) {
|
||
|
obj["bucketOptions"] = bucketOptionsProp
|
||
|
}
|
||
|
|
||
|
lockName, err := replaceVars(d, config, "customMetric/{{project}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
mutexKV.Lock(lockName)
|
||
|
defer mutexKV.Unlock(lockName)
|
||
|
|
||
|
url, err := replaceVars(d, config, "https://logging.googleapis.com/v2/projects/{{project}}/metrics/{{%name}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
log.Printf("[DEBUG] Updating Metric %q: %#v", d.Id(), obj)
|
||
|
_, err = sendRequestWithTimeout(config, "PUT", url, obj, d.Timeout(schema.TimeoutUpdate))
|
||
|
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("Error updating Metric %q: %s", d.Id(), err)
|
||
|
}
|
||
|
|
||
|
return resourceLoggingMetricRead(d, meta)
|
||
|
}
|
||
|
|
||
|
func resourceLoggingMetricDelete(d *schema.ResourceData, meta interface{}) error {
|
||
|
config := meta.(*Config)
|
||
|
|
||
|
lockName, err := replaceVars(d, config, "customMetric/{{project}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
mutexKV.Lock(lockName)
|
||
|
defer mutexKV.Unlock(lockName)
|
||
|
|
||
|
url, err := replaceVars(d, config, "https://logging.googleapis.com/v2/projects/{{project}}/metrics/{{%name}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
var obj map[string]interface{}
|
||
|
log.Printf("[DEBUG] Deleting Metric %q", d.Id())
|
||
|
res, err := sendRequestWithTimeout(config, "DELETE", url, obj, d.Timeout(schema.TimeoutDelete))
|
||
|
if err != nil {
|
||
|
return handleNotFoundError(err, d, "Metric")
|
||
|
}
|
||
|
|
||
|
log.Printf("[DEBUG] Finished deleting Metric %q: %#v", d.Id(), res)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func resourceLoggingMetricImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
||
|
|
||
|
config := meta.(*Config)
|
||
|
|
||
|
// current import_formats can't import fields with forward slashes in their value
|
||
|
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return []*schema.ResourceData{d}, nil
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricName(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricDescription(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricFilter(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricMetricDescriptor(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
if v == nil {
|
||
|
return nil
|
||
|
}
|
||
|
original := v.(map[string]interface{})
|
||
|
if len(original) == 0 {
|
||
|
return nil
|
||
|
}
|
||
|
transformed := make(map[string]interface{})
|
||
|
transformed["value_type"] =
|
||
|
flattenLoggingMetricMetricDescriptorValueType(original["valueType"], d)
|
||
|
transformed["metric_kind"] =
|
||
|
flattenLoggingMetricMetricDescriptorMetricKind(original["metricKind"], d)
|
||
|
transformed["labels"] =
|
||
|
flattenLoggingMetricMetricDescriptorLabels(original["labels"], d)
|
||
|
return []interface{}{transformed}
|
||
|
}
|
||
|
func flattenLoggingMetricMetricDescriptorValueType(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricMetricDescriptorMetricKind(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricMetricDescriptorLabels(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
if v == nil {
|
||
|
return v
|
||
|
}
|
||
|
l := v.([]interface{})
|
||
|
transformed := make([]interface{}, 0, len(l))
|
||
|
for _, raw := range l {
|
||
|
original := raw.(map[string]interface{})
|
||
|
if len(original) < 1 {
|
||
|
// Do not include empty json objects coming back from the api
|
||
|
continue
|
||
|
}
|
||
|
transformed = append(transformed, map[string]interface{}{
|
||
|
"key": flattenLoggingMetricMetricDescriptorLabelsKey(original["key"], d),
|
||
|
"description": flattenLoggingMetricMetricDescriptorLabelsDescription(original["description"], d),
|
||
|
"value_type": flattenLoggingMetricMetricDescriptorLabelsValueType(original["valueType"], d),
|
||
|
})
|
||
|
}
|
||
|
return transformed
|
||
|
}
|
||
|
func flattenLoggingMetricMetricDescriptorLabelsKey(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricMetricDescriptorLabelsDescription(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricMetricDescriptorLabelsValueType(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
if v == nil || v.(string) == "" {
|
||
|
return "STRING"
|
||
|
}
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricLabelExtractors(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricValueExtractor(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricBucketOptions(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
if v == nil {
|
||
|
return nil
|
||
|
}
|
||
|
original := v.(map[string]interface{})
|
||
|
if len(original) == 0 {
|
||
|
return nil
|
||
|
}
|
||
|
transformed := make(map[string]interface{})
|
||
|
transformed["linear_buckets"] =
|
||
|
flattenLoggingMetricBucketOptionsLinearBuckets(original["linearBuckets"], d)
|
||
|
transformed["exponential_buckets"] =
|
||
|
flattenLoggingMetricBucketOptionsExponentialBuckets(original["exponentialBuckets"], d)
|
||
|
transformed["explicit"] =
|
||
|
flattenLoggingMetricBucketOptionsExplicit(original["explicit"], d)
|
||
|
return []interface{}{transformed}
|
||
|
}
|
||
|
func flattenLoggingMetricBucketOptionsLinearBuckets(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
if v == nil {
|
||
|
return nil
|
||
|
}
|
||
|
original := v.(map[string]interface{})
|
||
|
if len(original) == 0 {
|
||
|
return nil
|
||
|
}
|
||
|
transformed := make(map[string]interface{})
|
||
|
transformed["num_finite_buckets"] =
|
||
|
flattenLoggingMetricBucketOptionsLinearBucketsNumFiniteBuckets(original["numFiniteBuckets"], d)
|
||
|
transformed["width"] =
|
||
|
flattenLoggingMetricBucketOptionsLinearBucketsWidth(original["width"], d)
|
||
|
transformed["offset"] =
|
||
|
flattenLoggingMetricBucketOptionsLinearBucketsOffset(original["offset"], d)
|
||
|
return []interface{}{transformed}
|
||
|
}
|
||
|
func flattenLoggingMetricBucketOptionsLinearBucketsNumFiniteBuckets(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
// Handles the string fixed64 format
|
||
|
if strVal, ok := v.(string); ok {
|
||
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
||
|
return intVal
|
||
|
} // let terraform core handle it if we can't convert the string to an int.
|
||
|
}
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricBucketOptionsLinearBucketsWidth(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
// Handles the string fixed64 format
|
||
|
if strVal, ok := v.(string); ok {
|
||
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
||
|
return intVal
|
||
|
} // let terraform core handle it if we can't convert the string to an int.
|
||
|
}
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricBucketOptionsLinearBucketsOffset(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricBucketOptionsExponentialBuckets(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
if v == nil {
|
||
|
return nil
|
||
|
}
|
||
|
original := v.(map[string]interface{})
|
||
|
if len(original) == 0 {
|
||
|
return nil
|
||
|
}
|
||
|
transformed := make(map[string]interface{})
|
||
|
transformed["num_finite_buckets"] =
|
||
|
flattenLoggingMetricBucketOptionsExponentialBucketsNumFiniteBuckets(original["numFiniteBuckets"], d)
|
||
|
transformed["growth_factor"] =
|
||
|
flattenLoggingMetricBucketOptionsExponentialBucketsGrowthFactor(original["growthFactor"], d)
|
||
|
transformed["scale"] =
|
||
|
flattenLoggingMetricBucketOptionsExponentialBucketsScale(original["scale"], d)
|
||
|
return []interface{}{transformed}
|
||
|
}
|
||
|
func flattenLoggingMetricBucketOptionsExponentialBucketsNumFiniteBuckets(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
// Handles the string fixed64 format
|
||
|
if strVal, ok := v.(string); ok {
|
||
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
||
|
return intVal
|
||
|
} // let terraform core handle it if we can't convert the string to an int.
|
||
|
}
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricBucketOptionsExponentialBucketsGrowthFactor(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
// Handles the string fixed64 format
|
||
|
if strVal, ok := v.(string); ok {
|
||
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
||
|
return intVal
|
||
|
} // let terraform core handle it if we can't convert the string to an int.
|
||
|
}
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricBucketOptionsExponentialBucketsScale(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenLoggingMetricBucketOptionsExplicit(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
if v == nil {
|
||
|
return nil
|
||
|
}
|
||
|
original := v.(map[string]interface{})
|
||
|
if len(original) == 0 {
|
||
|
return nil
|
||
|
}
|
||
|
transformed := make(map[string]interface{})
|
||
|
transformed["bounds"] =
|
||
|
flattenLoggingMetricBucketOptionsExplicitBounds(original["bounds"], d)
|
||
|
return []interface{}{transformed}
|
||
|
}
|
||
|
func flattenLoggingMetricBucketOptionsExplicitBounds(v interface{}, d *schema.ResourceData) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricFilter(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricMetricDescriptor(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
l := v.([]interface{})
|
||
|
if len(l) == 0 || l[0] == nil {
|
||
|
return nil, nil
|
||
|
}
|
||
|
raw := l[0]
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
|
||
|
transformedValueType, err := expandLoggingMetricMetricDescriptorValueType(original["value_type"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedValueType); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["valueType"] = transformedValueType
|
||
|
}
|
||
|
|
||
|
transformedMetricKind, err := expandLoggingMetricMetricDescriptorMetricKind(original["metric_kind"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedMetricKind); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["metricKind"] = transformedMetricKind
|
||
|
}
|
||
|
|
||
|
transformedLabels, err := expandLoggingMetricMetricDescriptorLabels(original["labels"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedLabels); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["labels"] = transformedLabels
|
||
|
}
|
||
|
|
||
|
return transformed, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricMetricDescriptorValueType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricMetricDescriptorMetricKind(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricMetricDescriptorLabels(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
l := v.([]interface{})
|
||
|
req := make([]interface{}, 0, len(l))
|
||
|
for _, raw := range l {
|
||
|
if raw == nil {
|
||
|
continue
|
||
|
}
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
|
||
|
transformedKey, err := expandLoggingMetricMetricDescriptorLabelsKey(original["key"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedKey); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["key"] = transformedKey
|
||
|
}
|
||
|
|
||
|
transformedDescription, err := expandLoggingMetricMetricDescriptorLabelsDescription(original["description"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedDescription); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["description"] = transformedDescription
|
||
|
}
|
||
|
|
||
|
transformedValueType, err := expandLoggingMetricMetricDescriptorLabelsValueType(original["value_type"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedValueType); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["valueType"] = transformedValueType
|
||
|
}
|
||
|
|
||
|
req = append(req, transformed)
|
||
|
}
|
||
|
return req, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricMetricDescriptorLabelsKey(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricMetricDescriptorLabelsDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricMetricDescriptorLabelsValueType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricLabelExtractors(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) {
|
||
|
if v == nil {
|
||
|
return map[string]string{}, nil
|
||
|
}
|
||
|
m := make(map[string]string)
|
||
|
for k, val := range v.(map[string]interface{}) {
|
||
|
m[k] = val.(string)
|
||
|
}
|
||
|
return m, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricValueExtractor(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricBucketOptions(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
l := v.([]interface{})
|
||
|
if len(l) == 0 || l[0] == nil {
|
||
|
return nil, nil
|
||
|
}
|
||
|
raw := l[0]
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
|
||
|
transformedLinearBuckets, err := expandLoggingMetricBucketOptionsLinearBuckets(original["linear_buckets"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedLinearBuckets); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["linearBuckets"] = transformedLinearBuckets
|
||
|
}
|
||
|
|
||
|
transformedExponentialBuckets, err := expandLoggingMetricBucketOptionsExponentialBuckets(original["exponential_buckets"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedExponentialBuckets); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["exponentialBuckets"] = transformedExponentialBuckets
|
||
|
}
|
||
|
|
||
|
transformedExplicit, err := expandLoggingMetricBucketOptionsExplicit(original["explicit"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedExplicit); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["explicit"] = transformedExplicit
|
||
|
}
|
||
|
|
||
|
return transformed, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricBucketOptionsLinearBuckets(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
l := v.([]interface{})
|
||
|
if len(l) == 0 || l[0] == nil {
|
||
|
return nil, nil
|
||
|
}
|
||
|
raw := l[0]
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
|
||
|
transformedNumFiniteBuckets, err := expandLoggingMetricBucketOptionsLinearBucketsNumFiniteBuckets(original["num_finite_buckets"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedNumFiniteBuckets); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["numFiniteBuckets"] = transformedNumFiniteBuckets
|
||
|
}
|
||
|
|
||
|
transformedWidth, err := expandLoggingMetricBucketOptionsLinearBucketsWidth(original["width"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedWidth); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["width"] = transformedWidth
|
||
|
}
|
||
|
|
||
|
transformedOffset, err := expandLoggingMetricBucketOptionsLinearBucketsOffset(original["offset"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedOffset); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["offset"] = transformedOffset
|
||
|
}
|
||
|
|
||
|
return transformed, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricBucketOptionsLinearBucketsNumFiniteBuckets(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricBucketOptionsLinearBucketsWidth(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricBucketOptionsLinearBucketsOffset(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricBucketOptionsExponentialBuckets(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
l := v.([]interface{})
|
||
|
if len(l) == 0 || l[0] == nil {
|
||
|
return nil, nil
|
||
|
}
|
||
|
raw := l[0]
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
|
||
|
transformedNumFiniteBuckets, err := expandLoggingMetricBucketOptionsExponentialBucketsNumFiniteBuckets(original["num_finite_buckets"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedNumFiniteBuckets); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["numFiniteBuckets"] = transformedNumFiniteBuckets
|
||
|
}
|
||
|
|
||
|
transformedGrowthFactor, err := expandLoggingMetricBucketOptionsExponentialBucketsGrowthFactor(original["growth_factor"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedGrowthFactor); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["growthFactor"] = transformedGrowthFactor
|
||
|
}
|
||
|
|
||
|
transformedScale, err := expandLoggingMetricBucketOptionsExponentialBucketsScale(original["scale"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedScale); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["scale"] = transformedScale
|
||
|
}
|
||
|
|
||
|
return transformed, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricBucketOptionsExponentialBucketsNumFiniteBuckets(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricBucketOptionsExponentialBucketsGrowthFactor(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricBucketOptionsExponentialBucketsScale(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricBucketOptionsExplicit(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
l := v.([]interface{})
|
||
|
if len(l) == 0 || l[0] == nil {
|
||
|
return nil, nil
|
||
|
}
|
||
|
raw := l[0]
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
|
||
|
transformedBounds, err := expandLoggingMetricBucketOptionsExplicitBounds(original["bounds"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedBounds); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["bounds"] = transformedBounds
|
||
|
}
|
||
|
|
||
|
return transformed, nil
|
||
|
}
|
||
|
|
||
|
func expandLoggingMetricBucketOptionsExplicitBounds(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|