Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support customized metric specification in autoscaling predictive scaling policy #22451

Merged
merged 9 commits into from
Mar 3, 2022
2 changes: 2 additions & 0 deletions .changelog/22451.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
```release-note:enhancement
resource/aws_autoscaling_policy: Add customized metric specification in `predictive_scaling_configuration` argument
90 changes: 88 additions & 2 deletions website/docs/r/autoscaling_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,12 @@ The following arguments are supported:

The following arguments are supported:

* `predefined_load_metric_specification` - (Optional) The load metric specification.
* `predefined_load_metric_specification` - (Optional) The predefined load metric specification.
* `predefined_metric_pair_specification` - (Optional) The metric pair specification from which Amazon EC2 Auto Scaling determines the appropriate scaling metric and load metric to use.
* `predefined_scaling_metric_specification` - (Optional) The scaling metric specification.
* `predefined_scaling_metric_specification` - (Optional) The predefined scaling metric specification.
* `customized_scaling_metric_specification` - (Optional) The customized scaling metric specification.
* `customized_load_metric_specification` - (Optional) The customized load metric specification.
* `customized_capacity_metric_specification` - (Optional) The customized capacity metric specification. The field is only valid when you use `customized_load_metric_specification`
gypdtc marked this conversation as resolved.
Show resolved Hide resolved
gypdtc marked this conversation as resolved.
Show resolved Hide resolved

##### predefined_load_metric_specification

Expand All @@ -184,6 +187,89 @@ The following arguments are supported:
* `predefined_metric_type` - (Required) Describes a scaling metric for a predictive scaling policy. Valid values are `ASGAverageCPUUtilization`, `ASGAverageNetworkIn`, `ASGAverageNetworkOut`, or `ALBRequestCountPerTarget`.
* `resource_label` - (Required) A label that uniquely identifies a specific Application Load Balancer target group from which to determine the request count served by your Auto Scaling group.

##### customized_scaling_metric_specification
The following arguments are supported:

* `metric_data_queries` - (Required) A list of up to 10 structure that defines custom scaling metric in predictive scaling policy
gypdtc marked this conversation as resolved.
Show resolved Hide resolved

##### customized_load_metric_specification
The following arguments are supported:
* `metric_data_queries` - (Required) A list of up to 10 structure that defines custom load metric in predictive scaling policy

##### customized_capacity_metric_specification
The following arguments are supported:
* `metric_data_queries` - (Required) A list of up to 10 structure that defines custom capacity metric in predictive scaling policy

##### metric_data_queries
The following arguments are supported:
* `id` - (Required) A short name for the metric used in predictive scaling policy.
* `expression` - (Optional) The math expression used on the returned metric. You must specify either `expression` or `metric_stat`, but not both.
* `metric_stat` - (Optional) A structure that defines CloudWatch metric to be used in predictive scaling policy. You must specify either `expression` or `metric_stat`, but not both.
* `label` - (Optional) A human-readable label for this metric or expression.
* `return_data` - (Optional) A boolean that indicates whether to return the timestamps and raw data values of this metric, the default it true

##### metric_stat
The following arguments are supported:
* `metric` - (Required) A structure that defines the CloudWatch metric to return, including the metric name, namespace, and dimensions.
* `stat` - (Required) The statistic of the metrics to return.
* `unit` - (Optional) The unit of the metrics to return.

##### metric
* `metric_name` - (Required) The name of the metric.
* `namespace` - (Required) The namespace of the metric.
* `dimensions` - (Optional) The dimensions of the metric.
gypdtc marked this conversation as resolved.
Show resolved Hide resolved

### Example predictive scaling policy using custom metric

```terraform
gypdtc marked this conversation as resolved.
Show resolved Hide resolved
resource "aws_autoscaling_policy" "example" {
# ... other configuration ...
gypdtc marked this conversation as resolved.
Show resolved Hide resolved

predictive_scaling_configuration {
metric_specification {
target_value = 10
customized_scaling_metric_specification {
metric_data_queries {
id = "scaling"
metric_stat {
metric {
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
dimensions {
name = "AutoScalingGroupName"
value = "ASG-myapp"
}
}
stat = "Average"
}
}
}
customized_load_metric_specification {
metric_data_queries {
id = "load_sum"
expression = "SUM(SEARCH('{AWS/EC2,AutoScalingGroupName} MetricName=\"CPUUtilization\" ASG-myapp', 'Sum', 3600))"
}
}
customized_capacity_metric_specification {
metric_data_queries {
id = "capacity_sum"
expression = "SUM(SEARCH('{AWS/AutoScaling,AutoScalingGroupName} MetricName=\"GroupInServiceIntances\" ASG-myapp', 'Average', 300))"
return_data = false
}
metric_data_queries {
id = "load_sum"
expression = "SUM(SEARCH('{AWS/EC2,AutoScalingGroupName} MetricName=\"CPUUtilization\" ASG-myapp', 'Sum', 300))"
return_data = false
}
metric_data_queries {
id = "weighted_average"
expression = "load_sum / capacity_sum"
}
}
}
}
}
```
## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down