@@ -170,6 +170,63 @@ be a positive float value. If not defined, the default is 0.8.`,
170170The metric cannot have negative values.
171171
172172The metric must have a value type of INT64 or DOUBLE.` ,
173+ },
174+ "filter" : {
175+ Type : schema .TypeString ,
176+ Optional : true ,
177+ Description : `A filter string to be used as the filter string for
178+ a Stackdriver Monitoring TimeSeries.list API call.
179+ This filter is used to select a specific TimeSeries for
180+ the purpose of autoscaling and to determine whether the metric
181+ is exporting per-instance or per-group data.
182+
183+ You can only use the AND operator for joining selectors.
184+ You can only use direct equality comparison operator (=) without
185+ any functions for each selector.
186+ You can specify the metric in both the filter string and in the
187+ metric field. However, if specified in both places, the metric must
188+ be identical.
189+
190+ The monitored resource type determines what kind of values are
191+ expected for the metric. If it is a gce_instance, the autoscaler
192+ expects the metric to include a separate TimeSeries for each
193+ instance in a group. In such a case, you cannot filter on resource
194+ labels.
195+
196+ If the resource type is any other value, the autoscaler expects
197+ this metric to contain values that apply to the entire autoscaled
198+ instance group and resource label filtering can be performed to
199+ point autoscaler at the correct TimeSeries to scale upon.
200+ This is called a per-group metric for the purpose of autoscaling.
201+
202+ If not specified, the type defaults to gce_instance.
203+
204+ You should provide a filter that is selective enough to pick just
205+ one TimeSeries for the autoscaled group or for each of the instances
206+ (if you are using gce_instance resource type). If multiple
207+ TimeSeries are returned upon the query execution, the autoscaler
208+ will sum their respective values to obtain its scaling value.` ,
209+ Default : "resource.type = gce_instance" ,
210+ },
211+ "single_instance_assignment" : {
212+ Type : schema .TypeFloat ,
213+ Optional : true ,
214+ Description : `If scaling is based on a per-group metric value that represents the
215+ total amount of work to be done or resource usage, set this value to
216+ an amount assigned for a single instance of the scaled group.
217+ The autoscaler will keep the number of instances proportional to the
218+ value of this metric, the metric itself should not change value due
219+ to group resizing.
220+
221+ For example, a good metric to use with the target is
222+ 'pubsub.googleapis.com/subscription/num_undelivered_messages'
223+ or a custom metric exporting the total number of requests coming to
224+ your instances.
225+
226+ A bad example would be a metric exporting an average or median
227+ latency, since this value can't include a chunk assignable to a
228+ single instance, it could be better used with utilization_target
229+ instead.` ,
173230 },
174231 "target" : {
175232 Type : schema .TypeFloat ,
@@ -890,9 +947,11 @@ func flattenComputeAutoscalerAutoscalingPolicyMetric(v interface{}, d *schema.Re
890947 continue
891948 }
892949 transformed = append (transformed , map [string ]interface {}{
893- "name" : flattenComputeAutoscalerAutoscalingPolicyMetricName (original ["metric" ], d , config ),
894- "target" : flattenComputeAutoscalerAutoscalingPolicyMetricTarget (original ["utilizationTarget" ], d , config ),
895- "type" : flattenComputeAutoscalerAutoscalingPolicyMetricType (original ["utilizationTargetType" ], d , config ),
950+ "name" : flattenComputeAutoscalerAutoscalingPolicyMetricName (original ["metric" ], d , config ),
951+ "single_instance_assignment" : flattenComputeAutoscalerAutoscalingPolicyMetricSingleInstanceAssignment (original ["singleInstanceAssignment" ], d , config ),
952+ "target" : flattenComputeAutoscalerAutoscalingPolicyMetricTarget (original ["utilizationTarget" ], d , config ),
953+ "type" : flattenComputeAutoscalerAutoscalingPolicyMetricType (original ["utilizationTargetType" ], d , config ),
954+ "filter" : flattenComputeAutoscalerAutoscalingPolicyMetricFilter (original ["filter" ], d , config ),
896955 })
897956 }
898957 return transformed
@@ -901,6 +960,10 @@ func flattenComputeAutoscalerAutoscalingPolicyMetricName(v interface{}, d *schem
901960 return v
902961}
903962
963+ func flattenComputeAutoscalerAutoscalingPolicyMetricSingleInstanceAssignment (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
964+ return v
965+ }
966+
904967func flattenComputeAutoscalerAutoscalingPolicyMetricTarget (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
905968 return v
906969}
@@ -909,6 +972,10 @@ func flattenComputeAutoscalerAutoscalingPolicyMetricType(v interface{}, d *schem
909972 return v
910973}
911974
975+ func flattenComputeAutoscalerAutoscalingPolicyMetricFilter (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
976+ return v
977+ }
978+
912979func flattenComputeAutoscalerAutoscalingPolicyLoadBalancingUtilization (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
913980 if v == nil {
914981 return nil
@@ -1217,6 +1284,13 @@ func expandComputeAutoscalerAutoscalingPolicyMetric(v interface{}, d tpgresource
12171284 transformed ["metric" ] = transformedName
12181285 }
12191286
1287+ transformedSingleInstanceAssignment , err := expandComputeAutoscalerAutoscalingPolicyMetricSingleInstanceAssignment (original ["single_instance_assignment" ], d , config )
1288+ if err != nil {
1289+ return nil , err
1290+ } else if val := reflect .ValueOf (transformedSingleInstanceAssignment ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1291+ transformed ["singleInstanceAssignment" ] = transformedSingleInstanceAssignment
1292+ }
1293+
12201294 transformedTarget , err := expandComputeAutoscalerAutoscalingPolicyMetricTarget (original ["target" ], d , config )
12211295 if err != nil {
12221296 return nil , err
@@ -1231,6 +1305,13 @@ func expandComputeAutoscalerAutoscalingPolicyMetric(v interface{}, d tpgresource
12311305 transformed ["utilizationTargetType" ] = transformedType
12321306 }
12331307
1308+ transformedFilter , err := expandComputeAutoscalerAutoscalingPolicyMetricFilter (original ["filter" ], d , config )
1309+ if err != nil {
1310+ return nil , err
1311+ } else if val := reflect .ValueOf (transformedFilter ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1312+ transformed ["filter" ] = transformedFilter
1313+ }
1314+
12341315 req = append (req , transformed )
12351316 }
12361317 return req , nil
@@ -1240,6 +1321,10 @@ func expandComputeAutoscalerAutoscalingPolicyMetricName(v interface{}, d tpgreso
12401321 return v , nil
12411322}
12421323
1324+ func expandComputeAutoscalerAutoscalingPolicyMetricSingleInstanceAssignment (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1325+ return v , nil
1326+ }
1327+
12431328func expandComputeAutoscalerAutoscalingPolicyMetricTarget (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
12441329 return v , nil
12451330}
@@ -1248,6 +1333,10 @@ func expandComputeAutoscalerAutoscalingPolicyMetricType(v interface{}, d tpgreso
12481333 return v , nil
12491334}
12501335
1336+ func expandComputeAutoscalerAutoscalingPolicyMetricFilter (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1337+ return v , nil
1338+ }
1339+
12511340func expandComputeAutoscalerAutoscalingPolicyLoadBalancingUtilization (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
12521341 l := v .([]interface {})
12531342 if len (l ) == 0 || l [0 ] == nil {
0 commit comments