diff --git a/google-beta/resource_compute_autoscaler.go b/google-beta/resource_compute_autoscaler.go index 3e0536ed5c..972afe25aa 100644 --- a/google-beta/resource_compute_autoscaler.go +++ b/google-beta/resource_compute_autoscaler.go @@ -108,6 +108,10 @@ func resourceComputeAutoscaler() *schema.Resource { Required: true, ValidateFunc: validation.StringInSlice([]string{"GAUGE", "DELTA_PER_SECOND", "DELTA_PER_MINUTE"}, false), }, + "filter": { + Type: schema.TypeString, + Optional: true, + }, }, }, }, @@ -484,6 +488,7 @@ func flattenComputeAutoscalerAutoscalingPolicyMetric(v interface{}) interface{} "name": flattenComputeAutoscalerAutoscalingPolicyMetricName(original["metric"]), "target": flattenComputeAutoscalerAutoscalingPolicyMetricTarget(original["utilizationTarget"]), "type": flattenComputeAutoscalerAutoscalingPolicyMetricType(original["utilizationTargetType"]), + "filter": flattenComputeAutoscalerAutoscalingPolicyMetricFilter(original["filter"]), }) } return transformed @@ -500,6 +505,10 @@ func flattenComputeAutoscalerAutoscalingPolicyMetricType(v interface{}) interfac return v } +func flattenComputeAutoscalerAutoscalingPolicyMetricFilter(v interface{}) interface{} { + return v +} + func flattenComputeAutoscalerAutoscalingPolicyLoadBalancingUtilization(v interface{}) interface{} { if v == nil { return nil @@ -656,6 +665,13 @@ func expandComputeAutoscalerAutoscalingPolicyMetric(v interface{}, d *schema.Res transformed["utilizationTargetType"] = transformedType } + transformedFilter, err := expandComputeAutoscalerAutoscalingPolicyMetricFilter(original["filter"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedFilter); val.IsValid() && !isEmptyValue(val) { + transformed["filter"] = transformedFilter + } + req = append(req, transformed) } return req, nil @@ -673,6 +689,10 @@ func expandComputeAutoscalerAutoscalingPolicyMetricType(v interface{}, d *schema return v, nil } +func expandComputeAutoscalerAutoscalingPolicyMetricFilter(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandComputeAutoscalerAutoscalingPolicyLoadBalancingUtilization(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { diff --git a/google-beta/resource_compute_region_autoscaler.go b/google-beta/resource_compute_region_autoscaler.go index 2536e9090d..0806acb85c 100644 --- a/google-beta/resource_compute_region_autoscaler.go +++ b/google-beta/resource_compute_region_autoscaler.go @@ -108,6 +108,10 @@ func resourceComputeRegionAutoscaler() *schema.Resource { Required: true, ValidateFunc: validation.StringInSlice([]string{"GAUGE", "DELTA_PER_SECOND", "DELTA_PER_MINUTE"}, false), }, + "filter": { + Type: schema.TypeString, + Optional: true, + }, }, }, }, @@ -483,6 +487,7 @@ func flattenComputeRegionAutoscalerAutoscalingPolicyMetric(v interface{}) interf "name": flattenComputeRegionAutoscalerAutoscalingPolicyMetricName(original["metric"]), "target": flattenComputeRegionAutoscalerAutoscalingPolicyMetricTarget(original["utilizationTarget"]), "type": flattenComputeRegionAutoscalerAutoscalingPolicyMetricType(original["utilizationTargetType"]), + "filter": flattenComputeRegionAutoscalerAutoscalingPolicyMetricFilter(original["filter"]), }) } return transformed @@ -499,6 +504,10 @@ func flattenComputeRegionAutoscalerAutoscalingPolicyMetricType(v interface{}) in return v } +func flattenComputeRegionAutoscalerAutoscalingPolicyMetricFilter(v interface{}) interface{} { + return v +} + func flattenComputeRegionAutoscalerAutoscalingPolicyLoadBalancingUtilization(v interface{}) interface{} { if v == nil { return nil @@ -652,6 +661,13 @@ func expandComputeRegionAutoscalerAutoscalingPolicyMetric(v interface{}, d *sche transformed["utilizationTargetType"] = transformedType } + transformedFilter, err := expandComputeRegionAutoscalerAutoscalingPolicyMetricFilter(original["filter"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedFilter); val.IsValid() && !isEmptyValue(val) { + transformed["filter"] = transformedFilter + } + req = append(req, transformed) } return req, nil @@ -669,6 +685,10 @@ func expandComputeRegionAutoscalerAutoscalingPolicyMetricType(v interface{}, d * return v, nil } +func expandComputeRegionAutoscalerAutoscalingPolicyMetricFilter(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandComputeRegionAutoscalerAutoscalingPolicyLoadBalancingUtilization(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { diff --git a/website/docs/r/compute_autoscaler.html.markdown b/website/docs/r/compute_autoscaler.html.markdown index 1d9841ae72..b14c260569 100644 --- a/website/docs/r/compute_autoscaler.html.markdown +++ b/website/docs/r/compute_autoscaler.html.markdown @@ -217,6 +217,36 @@ The `metric` block supports: Stackdriver Monitoring metric. Either GAUGE, DELTA_PER_SECOND, or DELTA_PER_MINUTE. +* `filter` - + (Optional) + A filter string to be used as the filter string for + a Stackdriver Monitoring TimeSeries.list API call. + This filter is used to select a specific TimeSeries for + the purpose of autoscaling and to determine whether the metric + is exporting per-instance or per-group data. + You can only use the AND operator for joining selectors. + You can only use direct equality comparison operator (=) without + any functions for each selector. + You can specify the metric in both the filter string and in the + metric field. However, if specified in both places, the metric must + be identical. + The monitored resource type determines what kind of values are + expected for the metric. If it is a gce_instance, the autoscaler + expects the metric to include a separate TimeSeries for each + instance in a group. In such a case, you cannot filter on resource + labels. + If the resource type is any other value, the autoscaler expects + this metric to contain values that apply to the entire autoscaled + instance group and resource label filtering can be performed to + point autoscaler at the correct TimeSeries to scale upon. + This is called a per-group metric for the purpose of autoscaling. + If not specified, the type defaults to gce_instance. + You should provide a filter that is selective enough to pick just + one TimeSeries for the autoscaled group or for each of the instances + (if you are using gce_instance resource type). If multiple + TimeSeries are returned upon the query execution, the autoscaler + will sum their respective values to obtain its scaling value. + The `load_balancing_utilization` block supports: * `target` - diff --git a/website/docs/r/compute_region_autoscaler.html.markdown b/website/docs/r/compute_region_autoscaler.html.markdown index 71c302358f..a1dcd28d42 100644 --- a/website/docs/r/compute_region_autoscaler.html.markdown +++ b/website/docs/r/compute_region_autoscaler.html.markdown @@ -217,6 +217,36 @@ The `metric` block supports: Stackdriver Monitoring metric. Either GAUGE, DELTA_PER_SECOND, or DELTA_PER_MINUTE. +* `filter` - + (Optional) + A filter string to be used as the filter string for + a Stackdriver Monitoring TimeSeries.list API call. + This filter is used to select a specific TimeSeries for + the purpose of autoscaling and to determine whether the metric + is exporting per-instance or per-group data. + You can only use the AND operator for joining selectors. + You can only use direct equality comparison operator (=) without + any functions for each selector. + You can specify the metric in both the filter string and in the + metric field. However, if specified in both places, the metric must + be identical. + The monitored resource type determines what kind of values are + expected for the metric. If it is a gce_instance, the autoscaler + expects the metric to include a separate TimeSeries for each + instance in a group. In such a case, you cannot filter on resource + labels. + If the resource type is any other value, the autoscaler expects + this metric to contain values that apply to the entire autoscaled + instance group and resource label filtering can be performed to + point autoscaler at the correct TimeSeries to scale upon. + This is called a per-group metric for the purpose of autoscaling. + If not specified, the type defaults to gce_instance. + You should provide a filter that is selective enough to pick just + one TimeSeries for the autoscaled group or for each of the instances + (if you are using gce_instance resource type). If multiple + TimeSeries are returned upon the query execution, the autoscaler + will sum their respective values to obtain its scaling value. + The `load_balancing_utilization` block supports: * `target` -