Skip to content

Commit 06b0616

Browse files
committed
add customized metrics support
1 parent 78a8bd6 commit 06b0616

File tree

6 files changed

+286
-6
lines changed

6 files changed

+286
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

examples/complete/main.tf

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,36 @@ module "ecs" {
7171
# predefined_scaling_metric_specification = {
7272
# predefined_metric_type = "ECSServiceAverageMemoryUtilization"
7373
# }
74-
# predefined_load_metric_specification = {
75-
# predefined_metric_type = "ECSServiceTotalMemoryUtilization"
74+
# predefined_metric_pair_specification = {
75+
# predefined_metric_type = "ECSServiceMemoryUtilization"
7676
# }
77-
predefined_metric_pair_specification = {
78-
predefined_metric_type = "ECSServiceMemoryUtilization"
77+
predefined_load_metric_specification = {
78+
predefined_metric_type = "ECSServiceTotalCPUUtilization"
79+
}
80+
customized_scaling_metric_specification = {
81+
metric_data_query = [
82+
{
83+
id = "memory_util"
84+
metric_stat = {
85+
stat = "Average"
86+
metric = {
87+
metric_name = "CPUUtilization"
88+
namespace = "AWS/ECS"
89+
dimension = [
90+
{
91+
name = "ServiceName"
92+
value = "ecsdemo-frontend"
93+
},
94+
{
95+
name = "ClusterName"
96+
value = "ex-complete"
97+
}
98+
]
99+
}
100+
}
101+
return_data = true
102+
}
103+
]
79104
}
80105
}
81106
}

modules/service/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ module "ecs_service" {
233233
| <a name="input_assign_public_ip"></a> [assign\_public\_ip](#input\_assign\_public\_ip) | Assign a public IP address to the ENI (Fargate launch type only) | `bool` | `false` | no |
234234
| <a name="input_autoscaling_max_capacity"></a> [autoscaling\_max\_capacity](#input\_autoscaling\_max\_capacity) | Maximum number of tasks to run in your service | `number` | `10` | no |
235235
| <a name="input_autoscaling_min_capacity"></a> [autoscaling\_min\_capacity](#input\_autoscaling\_min\_capacity) | Minimum number of tasks to run in your service | `number` | `1` | no |
236-
| <a name="input_autoscaling_policies"></a> [autoscaling\_policies](#input\_autoscaling\_policies) | Map of autoscaling policies to create for the service | <pre>map(object({<br/> name = optional(string) # Will fall back to the key name if not provided<br/> policy_type = optional(string, "TargetTrackingScaling")<br/> step_scaling_policy_configuration = optional(object({<br/> adjustment_type = optional(string)<br/> cooldown = optional(number)<br/> metric_aggregation_type = optional(string)<br/> min_adjustment_magnitude = optional(number)<br/> step_adjustment = optional(list(object({<br/> metric_interval_lower_bound = optional(string)<br/> metric_interval_upper_bound = optional(string)<br/> scaling_adjustment = number<br/> })))<br/> }))<br/> target_tracking_scaling_policy_configuration = optional(object({<br/> customized_metric_specification = optional(object({<br/> dimensions = optional(list(object({<br/> name = string<br/> value = string<br/> })))<br/> metric_name = optional(string)<br/> metrics = optional(list(object({<br/> expression = optional(string)<br/> id = string<br/> label = optional(string)<br/> metric_stat = optional(object({<br/> metric = object({<br/> dimensions = optional(list(object({<br/> name = string<br/> value = string<br/> })))<br/> metric_name = string<br/> namespace = string<br/> })<br/> stat = string<br/> unit = optional(string)<br/> }))<br/> return_data = optional(bool)<br/> })))<br/> namespace = optional(string)<br/> statistic = optional(string)<br/> unit = optional(string)<br/> }))<br/> disable_scale_in = optional(bool)<br/> predefined_metric_specification = optional(object({<br/> predefined_metric_type = string<br/> resource_label = optional(string)<br/> }))<br/> scale_in_cooldown = optional(number, 300)<br/> scale_out_cooldown = optional(number, 60)<br/> target_value = optional(number, 75)<br/> }))<br/> predictive_scaling_policy_configuration = optional(object({<br/> mode = optional(string, "ForecastAndScale")<br/> max_capacity_buffer = optional(number)<br/> max_capacity_breach_behavior = optional(string)<br/> scheduling_buffer_time = optional(number)<br/> metric_specification = object({<br/> target_value = number<br/> predefined_scaling_metric_specification = optional(object({<br/> predefined_metric_type = string<br/> resource_label = optional(string)<br/> }))<br/> predefined_load_metric_specification = optional(object({<br/> predefined_metric_type = string<br/> resource_label = optional(string)<br/> }))<br/> predefined_metric_pair_specification = optional(object({<br/> predefined_metric_type = string<br/> resource_label = optional(string)<br/> }))<br/> })<br/> }))<br/> }))</pre> | <pre>{<br/> "cpu": {<br/> "policy_type": "TargetTrackingScaling",<br/> "target_tracking_scaling_policy_configuration": {<br/> "predefined_metric_specification": {<br/> "predefined_metric_type": "ECSServiceAverageCPUUtilization"<br/> }<br/> }<br/> },<br/> "memory": {<br/> "policy_type": "TargetTrackingScaling",<br/> "target_tracking_scaling_policy_configuration": {<br/> "predefined_metric_specification": {<br/> "predefined_metric_type": "ECSServiceAverageMemoryUtilization"<br/> }<br/> }<br/> }<br/>}</pre> | no |
236+
| <a name="input_autoscaling_policies"></a> [autoscaling\_policies](#input\_autoscaling\_policies) | Map of autoscaling policies to create for the service | <pre>map(object({<br/> name = optional(string) # Will fall back to the key name if not provided<br/> policy_type = optional(string, "TargetTrackingScaling")<br/> step_scaling_policy_configuration = optional(object({<br/> adjustment_type = optional(string)<br/> cooldown = optional(number)<br/> metric_aggregation_type = optional(string)<br/> min_adjustment_magnitude = optional(number)<br/> step_adjustment = optional(list(object({<br/> metric_interval_lower_bound = optional(string)<br/> metric_interval_upper_bound = optional(string)<br/> scaling_adjustment = number<br/> })))<br/> }))<br/> target_tracking_scaling_policy_configuration = optional(object({<br/> customized_metric_specification = optional(object({<br/> dimensions = optional(list(object({<br/> name = string<br/> value = string<br/> })))<br/> metric_name = optional(string)<br/> metrics = optional(list(object({<br/> expression = optional(string)<br/> id = string<br/> label = optional(string)<br/> metric_stat = optional(object({<br/> metric = object({<br/> dimensions = optional(list(object({<br/> name = string<br/> value = string<br/> })))<br/> metric_name = string<br/> namespace = string<br/> })<br/> stat = string<br/> unit = optional(string)<br/> }))<br/> return_data = optional(bool)<br/> })))<br/> namespace = optional(string)<br/> statistic = optional(string)<br/> unit = optional(string)<br/> }))<br/> disable_scale_in = optional(bool)<br/> predefined_metric_specification = optional(object({<br/> predefined_metric_type = string<br/> resource_label = optional(string)<br/> }))<br/> scale_in_cooldown = optional(number, 300)<br/> scale_out_cooldown = optional(number, 60)<br/> target_value = optional(number, 75)<br/> }))<br/> predictive_scaling_policy_configuration = optional(object({<br/> mode = optional(string, "ForecastAndScale")<br/> max_capacity_buffer = optional(number)<br/> max_capacity_breach_behavior = optional(string)<br/> scheduling_buffer_time = optional(number)<br/> metric_specification = object({<br/> target_value = number<br/> predefined_scaling_metric_specification = optional(object({<br/> predefined_metric_type = string<br/> resource_label = optional(string)<br/> }))<br/> predefined_load_metric_specification = optional(object({<br/> predefined_metric_type = string<br/> resource_label = optional(string)<br/> }))<br/> predefined_metric_pair_specification = optional(object({<br/> predefined_metric_type = string<br/> resource_label = optional(string)<br/> }))<br/> customized_load_metric_specification = optional(object({<br/> metric_data_query = list(object({<br/> expression = optional(string)<br/> id = string<br/> label = optional(string)<br/> metric_stat = optional(object({<br/> metric = object({<br/> dimension = optional(list(object({<br/> name = string<br/> value = string<br/> })))<br/> metric_name = string<br/> namespace = string<br/> })<br/> stat = string<br/> unit = optional(string)<br/> }))<br/> return_data = optional(bool)<br/> }))<br/> }))<br/> customized_scaling_metric_specification = optional(object({<br/> metric_data_query = list(object({<br/> expression = optional(string)<br/> id = string<br/> label = optional(string)<br/> metric_stat = optional(object({<br/> metric = object({<br/> dimension = optional(list(object({<br/> name = string<br/> value = string<br/> })))<br/> metric_name = string<br/> namespace = string<br/> })<br/> stat = string<br/> unit = optional(string)<br/> }))<br/> return_data = optional(bool)<br/> }))<br/> }))<br/> customized_capacity_metric_specification = optional(object({<br/> metric_data_query = list(object({<br/> expression = optional(string)<br/> id = string<br/> label = optional(string)<br/> metric_stat = optional(object({<br/> metric = object({<br/> dimension = optional(list(object({<br/> name = string<br/> value = string<br/> })))<br/> metric_name = string<br/> namespace = string<br/> })<br/> stat = string<br/> unit = optional(string)<br/> }))<br/> return_data = optional(bool)<br/> }))<br/> }))<br/> })<br/> }))<br/> }))</pre> | <pre>{<br/> "cpu": {<br/> "policy_type": "TargetTrackingScaling",<br/> "target_tracking_scaling_policy_configuration": {<br/> "predefined_metric_specification": {<br/> "predefined_metric_type": "ECSServiceAverageCPUUtilization"<br/> }<br/> }<br/> },<br/> "memory": {<br/> "policy_type": "TargetTrackingScaling",<br/> "target_tracking_scaling_policy_configuration": {<br/> "predefined_metric_specification": {<br/> "predefined_metric_type": "ECSServiceAverageMemoryUtilization"<br/> }<br/> }<br/> }<br/>}</pre> | no |
237237
| <a name="input_autoscaling_scheduled_actions"></a> [autoscaling\_scheduled\_actions](#input\_autoscaling\_scheduled\_actions) | Map of autoscaling scheduled actions to create for the service | <pre>map(object({<br/> name = optional(string)<br/> min_capacity = number<br/> max_capacity = number<br/> schedule = string<br/> start_time = optional(string)<br/> end_time = optional(string)<br/> timezone = optional(string)<br/> }))</pre> | `null` | no |
238238
| <a name="input_availability_zone_rebalancing"></a> [availability\_zone\_rebalancing](#input\_availability\_zone\_rebalancing) | ECS automatically redistributes tasks within a service across Availability Zones (AZs) to mitigate the risk of impaired application availability due to underlying infrastructure failures and task lifecycle activities. The valid values are `ENABLED` and `DISABLED`. Defaults to `DISABLED` | `string` | `null` | no |
239239
| <a name="input_capacity_provider_strategy"></a> [capacity\_provider\_strategy](#input\_capacity\_provider\_strategy) | Capacity provider strategies to use for the service. Can be one or more | <pre>map(object({<br/> base = optional(number)<br/> capacity_provider = string<br/> weight = optional(number)<br/> }))</pre> | `null` | no |

modules/service/main.tf

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,141 @@ resource "aws_appautoscaling_policy" "this" {
16471647
resource_label = predefined_metric_pair_specification.value.resource_label
16481648
}
16491649
}
1650+
1651+
dynamic "customized_load_metric_specification" {
1652+
for_each = metric_specification.value.customized_load_metric_specification != null ? [metric_specification.value.customized_load_metric_specification] : []
1653+
1654+
content {
1655+
dynamic "metric_data_query" {
1656+
for_each = customized_load_metric_specification.value.metric_data_query
1657+
1658+
content {
1659+
expression = metric_data_query.value.expression
1660+
id = metric_data_query.value.id
1661+
label = metric_data_query.value.label
1662+
1663+
dynamic "metric_stat" {
1664+
for_each = metric_data_query.value.metric_stat != null ? [metric_data_query.value.metric_stat] : []
1665+
1666+
content {
1667+
dynamic "metric" {
1668+
for_each = [metric_stat.value.metric]
1669+
1670+
content {
1671+
dynamic "dimension" {
1672+
for_each = metric.value.dimension != null ? metric.value.dimension : []
1673+
1674+
content {
1675+
name = dimension.value.name
1676+
value = dimension.value.value
1677+
}
1678+
}
1679+
1680+
metric_name = metric.value.metric_name
1681+
namespace = metric.value.namespace
1682+
}
1683+
}
1684+
1685+
stat = metric_stat.value.stat
1686+
unit = metric_stat.value.unit
1687+
}
1688+
}
1689+
1690+
return_data = metric_data_query.value.return_data
1691+
}
1692+
}
1693+
}
1694+
}
1695+
1696+
dynamic "customized_scaling_metric_specification" {
1697+
for_each = metric_specification.value.customized_scaling_metric_specification != null ? [metric_specification.value.customized_scaling_metric_specification] : []
1698+
1699+
content {
1700+
dynamic "metric_data_query" {
1701+
for_each = customized_scaling_metric_specification.value.metric_data_query
1702+
1703+
content {
1704+
expression = metric_data_query.value.expression
1705+
id = metric_data_query.value.id
1706+
label = metric_data_query.value.label
1707+
1708+
dynamic "metric_stat" {
1709+
for_each = metric_data_query.value.metric_stat != null ? [metric_data_query.value.metric_stat] : []
1710+
1711+
content {
1712+
dynamic "metric" {
1713+
for_each = [metric_stat.value.metric]
1714+
1715+
content {
1716+
dynamic "dimension" {
1717+
for_each = metric.value.dimension != null ? metric.value.dimension : []
1718+
1719+
content {
1720+
name = dimension.value.name
1721+
value = dimension.value.value
1722+
}
1723+
}
1724+
1725+
metric_name = metric.value.metric_name
1726+
namespace = metric.value.namespace
1727+
}
1728+
}
1729+
1730+
stat = metric_stat.value.stat
1731+
unit = metric_stat.value.unit
1732+
}
1733+
}
1734+
1735+
return_data = metric_data_query.value.return_data
1736+
}
1737+
}
1738+
}
1739+
}
1740+
1741+
dynamic "customized_capacity_metric_specification" {
1742+
for_each = metric_specification.value.customized_capacity_metric_specification != null ? [metric_specification.value.customized_capacity_metric_specification] : []
1743+
1744+
content {
1745+
dynamic "metric_data_query" {
1746+
for_each = customized_capacity_metric_specification.value.metric_data_query
1747+
1748+
content {
1749+
expression = metric_data_query.value.expression
1750+
id = metric_data_query.value.id
1751+
label = metric_data_query.value.label
1752+
1753+
dynamic "metric_stat" {
1754+
for_each = metric_data_query.value.metric_stat != null ? [metric_data_query.value.metric_stat] : []
1755+
1756+
content {
1757+
dynamic "metric" {
1758+
for_each = [metric_stat.value.metric]
1759+
1760+
content {
1761+
dynamic "dimension" {
1762+
for_each = metric.value.dimension != null ? metric.value.dimension : []
1763+
1764+
content {
1765+
name = dimension.value.name
1766+
value = dimension.value.value
1767+
}
1768+
}
1769+
1770+
metric_name = metric.value.metric_name
1771+
namespace = metric.value.namespace
1772+
}
1773+
}
1774+
1775+
stat = metric_stat.value.stat
1776+
unit = metric_stat.value.unit
1777+
}
1778+
}
1779+
1780+
return_data = metric_data_query.value.return_data
1781+
}
1782+
}
1783+
}
1784+
}
16501785
}
16511786
}
16521787
}

0 commit comments

Comments
 (0)