-
Notifications
You must be signed in to change notification settings - Fork 5
/
autoscaling.tf
85 lines (73 loc) · 2.32 KB
/
autoscaling.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
resource "aws_appautoscaling_target" "concourse_workers_target" {
min_capacity = "${var.concourse_workers_min_instances}"
max_capacity = "${var.concourse_workers_max_instances}"
resource_id = "spot-fleet-request/${aws_spot_fleet_request.concourse_workers.id}"
role_arn = "${aws_iam_role.concourse_workers_scaling.arn}"
scalable_dimension = "ec2:spot-fleet-request:TargetCapacity"
service_namespace = "ec2"
}
resource "aws_appautoscaling_policy" "concourse_workers_scale" {
adjustment_type = "ChangeInCapacity"
cooldown = 60
metric_aggregation_type = "Maximum"
name = "concourse-workers-scaling"
resource_id = "spot-fleet-request/${aws_spot_fleet_request.concourse_workers.id}"
scalable_dimension = "ec2:spot-fleet-request:TargetCapacity"
service_namespace = "ec2"
step_adjustment {
metric_interval_lower_bound = 0
metric_interval_upper_bound = 10
scaling_adjustment = 1
}
step_adjustment {
metric_interval_lower_bound = 10
metric_interval_upper_bound = 20
scaling_adjustment = 2
}
step_adjustment {
metric_interval_lower_bound = 20
scaling_adjustment = 3
}
step_adjustment {
metric_interval_upper_bound = 0
scaling_adjustment = -1
}
depends_on = ["aws_appautoscaling_target.concourse_workers_target"]
}
resource "aws_iam_role" "concourse_workers_scaling" {
name = "iam_for_concourse_workers_scaling"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": ["application-autoscaling.amazonaws.com"]
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
data "aws_iam_policy_document" "concourse_workers_scaling" {
"statement" = {
"effect" = "Allow"
"actions" = [
"application-autoscaling:RegisterScalableTarget",
"cloudwatch:DescribeAlarms",
"ec2:DescribeSpotFleetRequests",
"ec2:ModifySpotFleetRequest",
]
"resources" = [
"*",
]
}
}
resource "aws_iam_role_policy" "concourse_workers_scaling" {
name = "iam_for_concourse_workers_scaling"
role = "${aws_iam_role.concourse_workers_scaling.id}"
policy = "${data.aws_iam_policy_document.concourse_workers_scaling.json}"
}