-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoscaling.tf
More file actions
82 lines (70 loc) · 2.43 KB
/
autoscaling.tf
File metadata and controls
82 lines (70 loc) · 2.43 KB
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
// CREATE AUTOSCALING GROUP
resource "aws_autoscaling_group" "autoscaling_group" {
name = "${aws_ecs_cluster.ecs_cluster.name}-${var.version_number}-asg"
desired_capacity = "${var.asg_desired_capacity}"
health_check_type = "EC2"
launch_configuration = "${aws_launch_configuration.launch_configuration.name}"
max_size = "${var.asg_max_size}"
min_size = "${var.asg_min_size}"
vpc_zone_identifier = ["${data.terraform_remote_state.vpc.private_subnet_ids}"]
lifecycle {
create_before_destroy = true
}
tag {
key = "Name"
value = "${aws_ecs_cluster.ecs_cluster.name}-asg"
propagate_at_launch = true
}
tag {
key = "name"
value = "${aws_ecs_cluster.ecs_cluster.name}-asg"
propagate_at_launch = true
}
tag {
key = "description"
value = "${var.environment_name}-ecs-cluster"
propagate_at_launch = true
}
tag {
key = "environment_name"
value = "${var.environment_name}"
propagate_at_launch = true
}
tag {
key = "service_name"
value = "ecs"
propagate_at_launch = true
}
tag {
key = "tier"
value = "${var.tier}"
propagate_at_launch = true
}
tag {
key = "service_name"
value = "ecs"
propagate_at_launch = true
}
}
// CREATE AUTOSCALING DOWN POLICY
resource "aws_autoscaling_policy" "scale_down_autoscaling_policy" {
name = "${aws_ecs_cluster.ecs_cluster.name}-asg-down"
adjustment_type = "ChangeInCapacity"
autoscaling_group_name = "${aws_autoscaling_group.autoscaling_group.name}"
cooldown = "${var.scaling_adjustment_down_cooldown}"
scaling_adjustment = "${var.scaling_adjustment_down}"
depends_on = [
"aws_autoscaling_group.autoscaling_group",
]
}
// CREATE AUTOSCALING UP POLICY
resource "aws_autoscaling_policy" "scale_up_autoscaling_policy" {
name = "${aws_ecs_cluster.ecs_cluster.name}-asg-up"
adjustment_type = "ChangeInCapacity"
autoscaling_group_name = "${aws_autoscaling_group.autoscaling_group.name}"
cooldown = "${var.scaling_adjustment_up_cooldown}"
scaling_adjustment = "${var.scaling_adjustment_up}"
depends_on = [
"aws_autoscaling_group.autoscaling_group",
]
}