Skip to content

Instantly share code, notes, and snippets.

@rgranadino
Created September 7, 2018 16:27
Show Gist options
  • Save rgranadino/710bda5f42e0bc194a169783262904d1 to your computer and use it in GitHub Desktop.
Save rgranadino/710bda5f42e0bc194a169783262904d1 to your computer and use it in GitHub Desktop.
terraform example of app autoscaling based on customized metric specification
resource "aws_appautoscaling_policy" "scale_out" {
name = "scale-up"
policy_type = "TargetTrackingScaling"
resource_id = "service/${data.terraform_remote_state.ecs_cluster.ecs_cluster_name}/${var.service_name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
target_tracking_scaling_policy_configuration {
target_value = "${var.scaling_target_value}"
scale_in_cooldown = "${var.scale_in_cooldown}"
scale_out_cooldown = "${var.scale_out_cooldown}"
customized_metric_specification {
dimensions = {
name = "ClusterName"
value = "${data.terraform_remote_state.ecs_cluster.ecs_cluster_name}"
}
dimensions = {
name = "ServiceName"
value = "${var.service_name}"
}
#CPUUtilization
metric_name = "${var.scaling_metric_name}"
namespace = "AWS/ECS"
#Maximum
statistic = "${var.scaling_metric_statistic}"
unit = "Percent"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment