mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 09:36:44 +00:00
1246 lines
47 KiB
Go
1246 lines
47 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"
|
||
|
|
||
|
"github.com/hashicorp/terraform/helper/schema"
|
||
|
"github.com/hashicorp/terraform/helper/validation"
|
||
|
)
|
||
|
|
||
|
func resourceMonitoringAlertPolicy() *schema.Resource {
|
||
|
return &schema.Resource{
|
||
|
Create: resourceMonitoringAlertPolicyCreate,
|
||
|
Read: resourceMonitoringAlertPolicyRead,
|
||
|
Update: resourceMonitoringAlertPolicyUpdate,
|
||
|
Delete: resourceMonitoringAlertPolicyDelete,
|
||
|
|
||
|
Importer: &schema.ResourceImporter{
|
||
|
State: resourceMonitoringAlertPolicyImport,
|
||
|
},
|
||
|
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"combiner": {
|
||
|
Type: schema.TypeString,
|
||
|
Required: true,
|
||
|
ValidateFunc: validation.StringInSlice([]string{"AND", "OR", "AND_WITH_MATCHING_RESOURCE"}, false),
|
||
|
},
|
||
|
"conditions": {
|
||
|
Type: schema.TypeList,
|
||
|
Required: true,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"display_name": {
|
||
|
Type: schema.TypeString,
|
||
|
Required: true,
|
||
|
},
|
||
|
"condition_absent": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
MaxItems: 1,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"duration": {
|
||
|
Type: schema.TypeString,
|
||
|
Required: true,
|
||
|
},
|
||
|
"aggregations": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"alignment_period": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"cross_series_reducer": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
ValidateFunc: validation.StringInSlice([]string{"REDUCE_NONE", "REDUCE_MEAN", "REDUCE_MIN", "REDUCE_MAX", "REDUCE_SUM", "REDUCE_STDDEV", "REDUCE_COUNT", "REDUCE_COUNT_TRUE", "REDUCE_COUNT_FALSE", "REDUCE_FRACTION_TRUE", "REDUCE_PERCENTILE_99", "REDUCE_PERCENTILE_95", "REDUCE_PERCENTILE_50", "REDUCE_PERCENTILE_05", ""}, false),
|
||
|
},
|
||
|
"group_by_fields": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
Elem: &schema.Schema{
|
||
|
Type: schema.TypeString,
|
||
|
},
|
||
|
},
|
||
|
"per_series_aligner": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
ValidateFunc: validation.StringInSlice([]string{"ALIGN_NONE", "ALIGN_DELTA", "ALIGN_RATE", "ALIGN_INTERPOLATE", "ALIGN_NEXT_OLDER", "ALIGN_MIN", "ALIGN_MAX", "ALIGN_MEAN", "ALIGN_COUNT", "ALIGN_SUM", "ALIGN_STDDEV", "ALIGN_COUNT_TRUE", "ALIGN_COUNT_FALSE", "ALIGN_FRACTION_TRUE", "ALIGN_PERCENTILE_99", "ALIGN_PERCENTILE_95", "ALIGN_PERCENTILE_50", "ALIGN_PERCENTILE_05", "ALIGN_PERCENT_CHANGE", ""}, false),
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
"filter": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"trigger": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
MaxItems: 1,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"count": {
|
||
|
Type: schema.TypeInt,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"percent": {
|
||
|
Type: schema.TypeFloat,
|
||
|
Optional: true,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
"condition_threshold": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
MaxItems: 1,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"comparison": {
|
||
|
Type: schema.TypeString,
|
||
|
Required: true,
|
||
|
ValidateFunc: validation.StringInSlice([]string{"COMPARISON_GT", "COMPARISON_GE", "COMPARISON_LT", "COMPARISON_LE", "COMPARISON_EQ", "COMPARISON_NE"}, false),
|
||
|
},
|
||
|
"duration": {
|
||
|
Type: schema.TypeString,
|
||
|
Required: true,
|
||
|
},
|
||
|
"aggregations": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"alignment_period": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"cross_series_reducer": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
ValidateFunc: validation.StringInSlice([]string{"REDUCE_NONE", "REDUCE_MEAN", "REDUCE_MIN", "REDUCE_MAX", "REDUCE_SUM", "REDUCE_STDDEV", "REDUCE_COUNT", "REDUCE_COUNT_TRUE", "REDUCE_COUNT_FALSE", "REDUCE_FRACTION_TRUE", "REDUCE_PERCENTILE_99", "REDUCE_PERCENTILE_95", "REDUCE_PERCENTILE_50", "REDUCE_PERCENTILE_05", ""}, false),
|
||
|
},
|
||
|
"group_by_fields": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
Elem: &schema.Schema{
|
||
|
Type: schema.TypeString,
|
||
|
},
|
||
|
},
|
||
|
"per_series_aligner": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
ValidateFunc: validation.StringInSlice([]string{"ALIGN_NONE", "ALIGN_DELTA", "ALIGN_RATE", "ALIGN_INTERPOLATE", "ALIGN_NEXT_OLDER", "ALIGN_MIN", "ALIGN_MAX", "ALIGN_MEAN", "ALIGN_COUNT", "ALIGN_SUM", "ALIGN_STDDEV", "ALIGN_COUNT_TRUE", "ALIGN_COUNT_FALSE", "ALIGN_FRACTION_TRUE", "ALIGN_PERCENTILE_99", "ALIGN_PERCENTILE_95", "ALIGN_PERCENTILE_50", "ALIGN_PERCENTILE_05", "ALIGN_PERCENT_CHANGE", ""}, false),
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
"denominator_aggregations": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"alignment_period": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"cross_series_reducer": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
ValidateFunc: validation.StringInSlice([]string{"REDUCE_NONE", "REDUCE_MEAN", "REDUCE_MIN", "REDUCE_MAX", "REDUCE_SUM", "REDUCE_STDDEV", "REDUCE_COUNT", "REDUCE_COUNT_TRUE", "REDUCE_COUNT_FALSE", "REDUCE_FRACTION_TRUE", "REDUCE_PERCENTILE_99", "REDUCE_PERCENTILE_95", "REDUCE_PERCENTILE_50", "REDUCE_PERCENTILE_05", ""}, false),
|
||
|
},
|
||
|
"group_by_fields": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
Elem: &schema.Schema{
|
||
|
Type: schema.TypeString,
|
||
|
},
|
||
|
},
|
||
|
"per_series_aligner": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
ValidateFunc: validation.StringInSlice([]string{"ALIGN_NONE", "ALIGN_DELTA", "ALIGN_RATE", "ALIGN_INTERPOLATE", "ALIGN_NEXT_OLDER", "ALIGN_MIN", "ALIGN_MAX", "ALIGN_MEAN", "ALIGN_COUNT", "ALIGN_SUM", "ALIGN_STDDEV", "ALIGN_COUNT_TRUE", "ALIGN_COUNT_FALSE", "ALIGN_FRACTION_TRUE", "ALIGN_PERCENTILE_99", "ALIGN_PERCENTILE_95", "ALIGN_PERCENTILE_50", "ALIGN_PERCENTILE_05", "ALIGN_PERCENT_CHANGE", ""}, false),
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
"denominator_filter": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"filter": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"threshold_value": {
|
||
|
Type: schema.TypeFloat,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"trigger": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
MaxItems: 1,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"count": {
|
||
|
Type: schema.TypeInt,
|
||
|
Optional: true,
|
||
|
},
|
||
|
"percent": {
|
||
|
Type: schema.TypeFloat,
|
||
|
Optional: true,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
"name": {
|
||
|
Type: schema.TypeString,
|
||
|
Computed: true,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
"display_name": {
|
||
|
Type: schema.TypeString,
|
||
|
Required: true,
|
||
|
},
|
||
|
"enabled": {
|
||
|
Type: schema.TypeBool,
|
||
|
Required: true,
|
||
|
},
|
||
|
"labels": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
Elem: &schema.Schema{
|
||
|
Type: schema.TypeString,
|
||
|
},
|
||
|
},
|
||
|
"notification_channels": {
|
||
|
Type: schema.TypeList,
|
||
|
Optional: true,
|
||
|
Elem: &schema.Schema{
|
||
|
Type: schema.TypeString,
|
||
|
},
|
||
|
},
|
||
|
"creation_record": {
|
||
|
Type: schema.TypeList,
|
||
|
Computed: true,
|
||
|
MaxItems: 1,
|
||
|
Elem: &schema.Resource{
|
||
|
Schema: map[string]*schema.Schema{
|
||
|
"mutate_time": {
|
||
|
Type: schema.TypeString,
|
||
|
Computed: true,
|
||
|
},
|
||
|
"mutated_by": {
|
||
|
Type: schema.TypeString,
|
||
|
Computed: true,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
"name": {
|
||
|
Type: schema.TypeString,
|
||
|
Computed: true,
|
||
|
},
|
||
|
"project": {
|
||
|
Type: schema.TypeString,
|
||
|
Optional: true,
|
||
|
Computed: true,
|
||
|
ForceNew: true,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func resourceMonitoringAlertPolicyCreate(d *schema.ResourceData, meta interface{}) error {
|
||
|
config := meta.(*Config)
|
||
|
|
||
|
obj := make(map[string]interface{})
|
||
|
displayNameProp, err := expandMonitoringAlertPolicyDisplayName(d.Get("display_name"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) {
|
||
|
obj["displayName"] = displayNameProp
|
||
|
}
|
||
|
combinerProp, err := expandMonitoringAlertPolicyCombiner(d.Get("combiner"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("combiner"); !isEmptyValue(reflect.ValueOf(combinerProp)) && (ok || !reflect.DeepEqual(v, combinerProp)) {
|
||
|
obj["combiner"] = combinerProp
|
||
|
}
|
||
|
enabledProp, err := expandMonitoringAlertPolicyEnabled(d.Get("enabled"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("enabled"); ok || !reflect.DeepEqual(v, enabledProp) {
|
||
|
obj["enabled"] = enabledProp
|
||
|
}
|
||
|
conditionsProp, err := expandMonitoringAlertPolicyConditions(d.Get("conditions"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("conditions"); !isEmptyValue(reflect.ValueOf(conditionsProp)) && (ok || !reflect.DeepEqual(v, conditionsProp)) {
|
||
|
obj["conditions"] = conditionsProp
|
||
|
}
|
||
|
notificationChannelsProp, err := expandMonitoringAlertPolicyNotificationChannels(d.Get("notification_channels"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("notification_channels"); !isEmptyValue(reflect.ValueOf(notificationChannelsProp)) && (ok || !reflect.DeepEqual(v, notificationChannelsProp)) {
|
||
|
obj["notificationChannels"] = notificationChannelsProp
|
||
|
}
|
||
|
labelsProp, err := expandMonitoringAlertPolicyLabels(d.Get("labels"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
|
||
|
obj["labels"] = labelsProp
|
||
|
}
|
||
|
|
||
|
lockName, err := replaceVars(d, config, "alertPolicy/{{project}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
mutexKV.Lock(lockName)
|
||
|
defer mutexKV.Unlock(lockName)
|
||
|
|
||
|
url, err := replaceVars(d, config, "https://monitoring.googleapis.com/v3/projects/{{project}}/alertPolicies")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
log.Printf("[DEBUG] Creating new AlertPolicy: %#v", obj)
|
||
|
res, err := sendRequest(config, "POST", url, obj)
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("Error creating AlertPolicy: %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 AlertPolicy %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 resourceMonitoringAlertPolicyRead(d, meta)
|
||
|
}
|
||
|
|
||
|
func resourceMonitoringAlertPolicyRead(d *schema.ResourceData, meta interface{}) error {
|
||
|
config := meta.(*Config)
|
||
|
|
||
|
url, err := replaceVars(d, config, "https://monitoring.googleapis.com/v3/{{name}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
res, err := sendRequest(config, "GET", url, nil)
|
||
|
if err != nil {
|
||
|
return handleNotFoundError(err, d, fmt.Sprintf("MonitoringAlertPolicy %q", d.Id()))
|
||
|
}
|
||
|
|
||
|
if err := d.Set("name", flattenMonitoringAlertPolicyName(res["name"])); err != nil {
|
||
|
return fmt.Errorf("Error reading AlertPolicy: %s", err)
|
||
|
}
|
||
|
if err := d.Set("display_name", flattenMonitoringAlertPolicyDisplayName(res["displayName"])); err != nil {
|
||
|
return fmt.Errorf("Error reading AlertPolicy: %s", err)
|
||
|
}
|
||
|
if err := d.Set("combiner", flattenMonitoringAlertPolicyCombiner(res["combiner"])); err != nil {
|
||
|
return fmt.Errorf("Error reading AlertPolicy: %s", err)
|
||
|
}
|
||
|
if err := d.Set("creation_record", flattenMonitoringAlertPolicyCreationRecord(res["creationRecord"])); err != nil {
|
||
|
return fmt.Errorf("Error reading AlertPolicy: %s", err)
|
||
|
}
|
||
|
if err := d.Set("enabled", flattenMonitoringAlertPolicyEnabled(res["enabled"])); err != nil {
|
||
|
return fmt.Errorf("Error reading AlertPolicy: %s", err)
|
||
|
}
|
||
|
if err := d.Set("conditions", flattenMonitoringAlertPolicyConditions(res["conditions"])); err != nil {
|
||
|
return fmt.Errorf("Error reading AlertPolicy: %s", err)
|
||
|
}
|
||
|
if err := d.Set("notification_channels", flattenMonitoringAlertPolicyNotificationChannels(res["notificationChannels"])); err != nil {
|
||
|
return fmt.Errorf("Error reading AlertPolicy: %s", err)
|
||
|
}
|
||
|
if err := d.Set("labels", flattenMonitoringAlertPolicyLabels(res["labels"])); err != nil {
|
||
|
return fmt.Errorf("Error reading AlertPolicy: %s", err)
|
||
|
}
|
||
|
project, err := getProject(d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
if err := d.Set("project", project); err != nil {
|
||
|
return fmt.Errorf("Error reading AlertPolicy: %s", err)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func resourceMonitoringAlertPolicyUpdate(d *schema.ResourceData, meta interface{}) error {
|
||
|
config := meta.(*Config)
|
||
|
|
||
|
obj := make(map[string]interface{})
|
||
|
displayNameProp, err := expandMonitoringAlertPolicyDisplayName(d.Get("display_name"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, displayNameProp)) {
|
||
|
obj["displayName"] = displayNameProp
|
||
|
}
|
||
|
combinerProp, err := expandMonitoringAlertPolicyCombiner(d.Get("combiner"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("combiner"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, combinerProp)) {
|
||
|
obj["combiner"] = combinerProp
|
||
|
}
|
||
|
enabledProp, err := expandMonitoringAlertPolicyEnabled(d.Get("enabled"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("enabled"); ok || !reflect.DeepEqual(v, enabledProp) {
|
||
|
obj["enabled"] = enabledProp
|
||
|
}
|
||
|
conditionsProp, err := expandMonitoringAlertPolicyConditions(d.Get("conditions"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("conditions"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, conditionsProp)) {
|
||
|
obj["conditions"] = conditionsProp
|
||
|
}
|
||
|
notificationChannelsProp, err := expandMonitoringAlertPolicyNotificationChannels(d.Get("notification_channels"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("notification_channels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, notificationChannelsProp)) {
|
||
|
obj["notificationChannels"] = notificationChannelsProp
|
||
|
}
|
||
|
labelsProp, err := expandMonitoringAlertPolicyLabels(d.Get("labels"), d, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
|
||
|
obj["labels"] = labelsProp
|
||
|
}
|
||
|
|
||
|
lockName, err := replaceVars(d, config, "alertPolicy/{{project}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
mutexKV.Lock(lockName)
|
||
|
defer mutexKV.Unlock(lockName)
|
||
|
|
||
|
url, err := replaceVars(d, config, "https://monitoring.googleapis.com/v3/{{name}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
log.Printf("[DEBUG] Updating AlertPolicy %q: %#v", d.Id(), obj)
|
||
|
_, err = sendRequest(config, "PATCH", url, obj)
|
||
|
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("Error updating AlertPolicy %q: %s", d.Id(), err)
|
||
|
}
|
||
|
|
||
|
return resourceMonitoringAlertPolicyRead(d, meta)
|
||
|
}
|
||
|
|
||
|
func resourceMonitoringAlertPolicyDelete(d *schema.ResourceData, meta interface{}) error {
|
||
|
config := meta.(*Config)
|
||
|
|
||
|
lockName, err := replaceVars(d, config, "alertPolicy/{{project}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
mutexKV.Lock(lockName)
|
||
|
defer mutexKV.Unlock(lockName)
|
||
|
|
||
|
url, err := replaceVars(d, config, "https://monitoring.googleapis.com/v3/{{name}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
var obj map[string]interface{}
|
||
|
log.Printf("[DEBUG] Deleting AlertPolicy %q", d.Id())
|
||
|
res, err := sendRequest(config, "DELETE", url, obj)
|
||
|
if err != nil {
|
||
|
return handleNotFoundError(err, d, "AlertPolicy")
|
||
|
}
|
||
|
|
||
|
log.Printf("[DEBUG] Finished deleting AlertPolicy %q: %#v", d.Id(), res)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func resourceMonitoringAlertPolicyImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
||
|
|
||
|
config := meta.(*Config)
|
||
|
|
||
|
// current import_formats can't import id's with forward slashes in them.
|
||
|
parseImportId([]string{"(?P<name>.+)"}, d, config)
|
||
|
|
||
|
return []*schema.ResourceData{d}, nil
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyName(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyDisplayName(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyCombiner(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyCreationRecord(v interface{}) interface{} {
|
||
|
if v == nil {
|
||
|
return nil
|
||
|
}
|
||
|
original := v.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
transformed["mutate_time"] =
|
||
|
flattenMonitoringAlertPolicyCreationRecordMutateTime(original["mutateTime"])
|
||
|
transformed["mutated_by"] =
|
||
|
flattenMonitoringAlertPolicyCreationRecordMutatedBy(original["mutatedBy"])
|
||
|
return []interface{}{transformed}
|
||
|
}
|
||
|
func flattenMonitoringAlertPolicyCreationRecordMutateTime(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyCreationRecordMutatedBy(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyEnabled(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditions(v interface{}) interface{} {
|
||
|
if v == nil {
|
||
|
return v
|
||
|
}
|
||
|
l := v.([]interface{})
|
||
|
transformed := make([]interface{}, 0, len(l))
|
||
|
for _, raw := range l {
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed = append(transformed, map[string]interface{}{
|
||
|
"condition_absent": flattenMonitoringAlertPolicyConditionsConditionAbsent(original["conditionAbsent"]),
|
||
|
"name": flattenMonitoringAlertPolicyConditionsName(original["name"]),
|
||
|
"condition_threshold": flattenMonitoringAlertPolicyConditionsConditionThreshold(original["conditionThreshold"]),
|
||
|
"display_name": flattenMonitoringAlertPolicyConditionsDisplayName(original["displayName"]),
|
||
|
})
|
||
|
}
|
||
|
return transformed
|
||
|
}
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionAbsent(v interface{}) interface{} {
|
||
|
if v == nil {
|
||
|
return nil
|
||
|
}
|
||
|
original := v.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
transformed["aggregations"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionAbsentAggregations(original["aggregations"])
|
||
|
transformed["trigger"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionAbsentTrigger(original["trigger"])
|
||
|
transformed["duration"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionAbsentDuration(original["duration"])
|
||
|
transformed["filter"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionAbsentFilter(original["filter"])
|
||
|
return []interface{}{transformed}
|
||
|
}
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionAbsentAggregations(v interface{}) interface{} {
|
||
|
if v == nil {
|
||
|
return v
|
||
|
}
|
||
|
l := v.([]interface{})
|
||
|
transformed := make([]interface{}, 0, len(l))
|
||
|
for _, raw := range l {
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed = append(transformed, map[string]interface{}{
|
||
|
"per_series_aligner": flattenMonitoringAlertPolicyConditionsConditionAbsentAggregationsPerSeriesAligner(original["perSeriesAligner"]),
|
||
|
"group_by_fields": flattenMonitoringAlertPolicyConditionsConditionAbsentAggregationsGroupByFields(original["groupByFields"]),
|
||
|
"alignment_period": flattenMonitoringAlertPolicyConditionsConditionAbsentAggregationsAlignmentPeriod(original["alignmentPeriod"]),
|
||
|
"cross_series_reducer": flattenMonitoringAlertPolicyConditionsConditionAbsentAggregationsCrossSeriesReducer(original["crossSeriesReducer"]),
|
||
|
})
|
||
|
}
|
||
|
return transformed
|
||
|
}
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionAbsentAggregationsPerSeriesAligner(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionAbsentAggregationsGroupByFields(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionAbsentAggregationsAlignmentPeriod(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionAbsentAggregationsCrossSeriesReducer(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionAbsentTrigger(v interface{}) interface{} {
|
||
|
if v == nil {
|
||
|
return nil
|
||
|
}
|
||
|
original := v.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
transformed["percent"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionAbsentTriggerPercent(original["percent"])
|
||
|
transformed["count"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionAbsentTriggerCount(original["count"])
|
||
|
return []interface{}{transformed}
|
||
|
}
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionAbsentTriggerPercent(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionAbsentTriggerCount(v interface{}) 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 flattenMonitoringAlertPolicyConditionsConditionAbsentDuration(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionAbsentFilter(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsName(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThreshold(v interface{}) interface{} {
|
||
|
if v == nil {
|
||
|
return nil
|
||
|
}
|
||
|
original := v.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
transformed["threshold_value"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionThresholdThresholdValue(original["thresholdValue"])
|
||
|
transformed["denominator_filter"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionThresholdDenominatorFilter(original["denominatorFilter"])
|
||
|
transformed["denominator_aggregations"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregations(original["denominatorAggregations"])
|
||
|
transformed["duration"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionThresholdDuration(original["duration"])
|
||
|
transformed["comparison"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionThresholdComparison(original["comparison"])
|
||
|
transformed["trigger"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionThresholdTrigger(original["trigger"])
|
||
|
transformed["aggregations"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionThresholdAggregations(original["aggregations"])
|
||
|
transformed["filter"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionThresholdFilter(original["filter"])
|
||
|
return []interface{}{transformed}
|
||
|
}
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdThresholdValue(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdDenominatorFilter(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregations(v interface{}) interface{} {
|
||
|
if v == nil {
|
||
|
return v
|
||
|
}
|
||
|
l := v.([]interface{})
|
||
|
transformed := make([]interface{}, 0, len(l))
|
||
|
for _, raw := range l {
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed = append(transformed, map[string]interface{}{
|
||
|
"per_series_aligner": flattenMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsPerSeriesAligner(original["perSeriesAligner"]),
|
||
|
"group_by_fields": flattenMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsGroupByFields(original["groupByFields"]),
|
||
|
"alignment_period": flattenMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsAlignmentPeriod(original["alignmentPeriod"]),
|
||
|
"cross_series_reducer": flattenMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsCrossSeriesReducer(original["crossSeriesReducer"]),
|
||
|
})
|
||
|
}
|
||
|
return transformed
|
||
|
}
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsPerSeriesAligner(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsGroupByFields(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsAlignmentPeriod(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsCrossSeriesReducer(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdDuration(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdComparison(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdTrigger(v interface{}) interface{} {
|
||
|
if v == nil {
|
||
|
return nil
|
||
|
}
|
||
|
original := v.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
transformed["percent"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionThresholdTriggerPercent(original["percent"])
|
||
|
transformed["count"] =
|
||
|
flattenMonitoringAlertPolicyConditionsConditionThresholdTriggerCount(original["count"])
|
||
|
return []interface{}{transformed}
|
||
|
}
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdTriggerPercent(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdTriggerCount(v interface{}) 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 flattenMonitoringAlertPolicyConditionsConditionThresholdAggregations(v interface{}) interface{} {
|
||
|
if v == nil {
|
||
|
return v
|
||
|
}
|
||
|
l := v.([]interface{})
|
||
|
transformed := make([]interface{}, 0, len(l))
|
||
|
for _, raw := range l {
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed = append(transformed, map[string]interface{}{
|
||
|
"per_series_aligner": flattenMonitoringAlertPolicyConditionsConditionThresholdAggregationsPerSeriesAligner(original["perSeriesAligner"]),
|
||
|
"group_by_fields": flattenMonitoringAlertPolicyConditionsConditionThresholdAggregationsGroupByFields(original["groupByFields"]),
|
||
|
"alignment_period": flattenMonitoringAlertPolicyConditionsConditionThresholdAggregationsAlignmentPeriod(original["alignmentPeriod"]),
|
||
|
"cross_series_reducer": flattenMonitoringAlertPolicyConditionsConditionThresholdAggregationsCrossSeriesReducer(original["crossSeriesReducer"]),
|
||
|
})
|
||
|
}
|
||
|
return transformed
|
||
|
}
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdAggregationsPerSeriesAligner(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdAggregationsGroupByFields(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdAggregationsAlignmentPeriod(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdAggregationsCrossSeriesReducer(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsConditionThresholdFilter(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyConditionsDisplayName(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyNotificationChannels(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func flattenMonitoringAlertPolicyLabels(v interface{}) interface{} {
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyDisplayName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyCombiner(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyEnabled(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditions(v interface{}, d *schema.ResourceData, 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{})
|
||
|
|
||
|
transformedConditionAbsent, err := expandMonitoringAlertPolicyConditionsConditionAbsent(original["condition_absent"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedConditionAbsent); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["conditionAbsent"] = transformedConditionAbsent
|
||
|
}
|
||
|
|
||
|
transformedName, err := expandMonitoringAlertPolicyConditionsName(original["name"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedName); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["name"] = transformedName
|
||
|
}
|
||
|
|
||
|
transformedConditionThreshold, err := expandMonitoringAlertPolicyConditionsConditionThreshold(original["condition_threshold"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedConditionThreshold); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["conditionThreshold"] = transformedConditionThreshold
|
||
|
}
|
||
|
|
||
|
transformedDisplayName, err := expandMonitoringAlertPolicyConditionsDisplayName(original["display_name"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedDisplayName); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["displayName"] = transformedDisplayName
|
||
|
}
|
||
|
|
||
|
req = append(req, transformed)
|
||
|
}
|
||
|
return req, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionAbsent(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
l := v.([]interface{})
|
||
|
if len(l) == 0 {
|
||
|
return nil, nil
|
||
|
}
|
||
|
raw := l[0]
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
|
||
|
transformedAggregations, err := expandMonitoringAlertPolicyConditionsConditionAbsentAggregations(original["aggregations"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedAggregations); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["aggregations"] = transformedAggregations
|
||
|
}
|
||
|
|
||
|
transformedTrigger, err := expandMonitoringAlertPolicyConditionsConditionAbsentTrigger(original["trigger"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedTrigger); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["trigger"] = transformedTrigger
|
||
|
}
|
||
|
|
||
|
transformedDuration, err := expandMonitoringAlertPolicyConditionsConditionAbsentDuration(original["duration"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedDuration); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["duration"] = transformedDuration
|
||
|
}
|
||
|
|
||
|
transformedFilter, err := expandMonitoringAlertPolicyConditionsConditionAbsentFilter(original["filter"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedFilter); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["filter"] = transformedFilter
|
||
|
}
|
||
|
|
||
|
return transformed, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionAbsentAggregations(v interface{}, d *schema.ResourceData, 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{})
|
||
|
|
||
|
transformedPerSeriesAligner, err := expandMonitoringAlertPolicyConditionsConditionAbsentAggregationsPerSeriesAligner(original["per_series_aligner"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedPerSeriesAligner); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["perSeriesAligner"] = transformedPerSeriesAligner
|
||
|
}
|
||
|
|
||
|
transformedGroupByFields, err := expandMonitoringAlertPolicyConditionsConditionAbsentAggregationsGroupByFields(original["group_by_fields"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedGroupByFields); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["groupByFields"] = transformedGroupByFields
|
||
|
}
|
||
|
|
||
|
transformedAlignmentPeriod, err := expandMonitoringAlertPolicyConditionsConditionAbsentAggregationsAlignmentPeriod(original["alignment_period"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedAlignmentPeriod); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["alignmentPeriod"] = transformedAlignmentPeriod
|
||
|
}
|
||
|
|
||
|
transformedCrossSeriesReducer, err := expandMonitoringAlertPolicyConditionsConditionAbsentAggregationsCrossSeriesReducer(original["cross_series_reducer"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedCrossSeriesReducer); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["crossSeriesReducer"] = transformedCrossSeriesReducer
|
||
|
}
|
||
|
|
||
|
req = append(req, transformed)
|
||
|
}
|
||
|
return req, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionAbsentAggregationsPerSeriesAligner(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionAbsentAggregationsGroupByFields(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionAbsentAggregationsAlignmentPeriod(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionAbsentAggregationsCrossSeriesReducer(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionAbsentTrigger(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
l := v.([]interface{})
|
||
|
if len(l) == 0 {
|
||
|
return nil, nil
|
||
|
}
|
||
|
raw := l[0]
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
|
||
|
transformedPercent, err := expandMonitoringAlertPolicyConditionsConditionAbsentTriggerPercent(original["percent"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedPercent); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["percent"] = transformedPercent
|
||
|
}
|
||
|
|
||
|
transformedCount, err := expandMonitoringAlertPolicyConditionsConditionAbsentTriggerCount(original["count"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedCount); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["count"] = transformedCount
|
||
|
}
|
||
|
|
||
|
return transformed, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionAbsentTriggerPercent(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionAbsentTriggerCount(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionAbsentDuration(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionAbsentFilter(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThreshold(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
l := v.([]interface{})
|
||
|
if len(l) == 0 {
|
||
|
return nil, nil
|
||
|
}
|
||
|
raw := l[0]
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
|
||
|
transformedThresholdValue, err := expandMonitoringAlertPolicyConditionsConditionThresholdThresholdValue(original["threshold_value"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedThresholdValue); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["thresholdValue"] = transformedThresholdValue
|
||
|
}
|
||
|
|
||
|
transformedDenominatorFilter, err := expandMonitoringAlertPolicyConditionsConditionThresholdDenominatorFilter(original["denominator_filter"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedDenominatorFilter); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["denominatorFilter"] = transformedDenominatorFilter
|
||
|
}
|
||
|
|
||
|
transformedDenominatorAggregations, err := expandMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregations(original["denominator_aggregations"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedDenominatorAggregations); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["denominatorAggregations"] = transformedDenominatorAggregations
|
||
|
}
|
||
|
|
||
|
transformedDuration, err := expandMonitoringAlertPolicyConditionsConditionThresholdDuration(original["duration"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedDuration); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["duration"] = transformedDuration
|
||
|
}
|
||
|
|
||
|
transformedComparison, err := expandMonitoringAlertPolicyConditionsConditionThresholdComparison(original["comparison"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedComparison); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["comparison"] = transformedComparison
|
||
|
}
|
||
|
|
||
|
transformedTrigger, err := expandMonitoringAlertPolicyConditionsConditionThresholdTrigger(original["trigger"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedTrigger); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["trigger"] = transformedTrigger
|
||
|
}
|
||
|
|
||
|
transformedAggregations, err := expandMonitoringAlertPolicyConditionsConditionThresholdAggregations(original["aggregations"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedAggregations); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["aggregations"] = transformedAggregations
|
||
|
}
|
||
|
|
||
|
transformedFilter, err := expandMonitoringAlertPolicyConditionsConditionThresholdFilter(original["filter"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedFilter); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["filter"] = transformedFilter
|
||
|
}
|
||
|
|
||
|
return transformed, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdThresholdValue(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdDenominatorFilter(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregations(v interface{}, d *schema.ResourceData, 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{})
|
||
|
|
||
|
transformedPerSeriesAligner, err := expandMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsPerSeriesAligner(original["per_series_aligner"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedPerSeriesAligner); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["perSeriesAligner"] = transformedPerSeriesAligner
|
||
|
}
|
||
|
|
||
|
transformedGroupByFields, err := expandMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsGroupByFields(original["group_by_fields"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedGroupByFields); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["groupByFields"] = transformedGroupByFields
|
||
|
}
|
||
|
|
||
|
transformedAlignmentPeriod, err := expandMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsAlignmentPeriod(original["alignment_period"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedAlignmentPeriod); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["alignmentPeriod"] = transformedAlignmentPeriod
|
||
|
}
|
||
|
|
||
|
transformedCrossSeriesReducer, err := expandMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsCrossSeriesReducer(original["cross_series_reducer"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedCrossSeriesReducer); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["crossSeriesReducer"] = transformedCrossSeriesReducer
|
||
|
}
|
||
|
|
||
|
req = append(req, transformed)
|
||
|
}
|
||
|
return req, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsPerSeriesAligner(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsGroupByFields(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsAlignmentPeriod(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdDenominatorAggregationsCrossSeriesReducer(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdDuration(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdComparison(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdTrigger(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
l := v.([]interface{})
|
||
|
if len(l) == 0 {
|
||
|
return nil, nil
|
||
|
}
|
||
|
raw := l[0]
|
||
|
original := raw.(map[string]interface{})
|
||
|
transformed := make(map[string]interface{})
|
||
|
|
||
|
transformedPercent, err := expandMonitoringAlertPolicyConditionsConditionThresholdTriggerPercent(original["percent"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedPercent); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["percent"] = transformedPercent
|
||
|
}
|
||
|
|
||
|
transformedCount, err := expandMonitoringAlertPolicyConditionsConditionThresholdTriggerCount(original["count"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedCount); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["count"] = transformedCount
|
||
|
}
|
||
|
|
||
|
return transformed, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdTriggerPercent(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdTriggerCount(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdAggregations(v interface{}, d *schema.ResourceData, 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{})
|
||
|
|
||
|
transformedPerSeriesAligner, err := expandMonitoringAlertPolicyConditionsConditionThresholdAggregationsPerSeriesAligner(original["per_series_aligner"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedPerSeriesAligner); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["perSeriesAligner"] = transformedPerSeriesAligner
|
||
|
}
|
||
|
|
||
|
transformedGroupByFields, err := expandMonitoringAlertPolicyConditionsConditionThresholdAggregationsGroupByFields(original["group_by_fields"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedGroupByFields); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["groupByFields"] = transformedGroupByFields
|
||
|
}
|
||
|
|
||
|
transformedAlignmentPeriod, err := expandMonitoringAlertPolicyConditionsConditionThresholdAggregationsAlignmentPeriod(original["alignment_period"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedAlignmentPeriod); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["alignmentPeriod"] = transformedAlignmentPeriod
|
||
|
}
|
||
|
|
||
|
transformedCrossSeriesReducer, err := expandMonitoringAlertPolicyConditionsConditionThresholdAggregationsCrossSeriesReducer(original["cross_series_reducer"], d, config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if val := reflect.ValueOf(transformedCrossSeriesReducer); val.IsValid() && !isEmptyValue(val) {
|
||
|
transformed["crossSeriesReducer"] = transformedCrossSeriesReducer
|
||
|
}
|
||
|
|
||
|
req = append(req, transformed)
|
||
|
}
|
||
|
return req, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdAggregationsPerSeriesAligner(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdAggregationsGroupByFields(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdAggregationsAlignmentPeriod(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdAggregationsCrossSeriesReducer(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsConditionThresholdFilter(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyConditionsDisplayName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyNotificationChannels(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|
||
|
|
||
|
func expandMonitoringAlertPolicyLabels(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
||
|
return v, nil
|
||
|
}
|