-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp-servers.tf
58 lines (48 loc) · 1.35 KB
/
app-servers.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
resource "aws_elb" "elb_app" {
name = "elb"
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
health_check {
healthy_threshold = 3
unhealthy_threshold = 2
timeout = 10
target = "HTTP:80/"
interval = 30
}
cross_zone_load_balancing = true
idle_timeout = 60
subnets = ["${split(",", module.network.public_subnet_ids)}"]
security_groups = ["${aws_security_group.elb_web.id}"]
tags {
Name = "elb"
}
}
resource "aws_autoscaling_group" "asg_app" {
lifecycle { create_before_destroy = true }
name = "asg-app - ${aws_launch_configuration.lc_app.name}"
max_size = 2
min_size = 1
wait_for_elb_capacity = 1
desired_capacity = 2
health_check_grace_period = 300
health_check_type = "ELB"
launch_configuration = "${aws_launch_configuration.lc_app.id}"
load_balancers = ["${aws_elb.elb_app.id}"]
vpc_zone_identifier = ["${split(",", module.network.private_subnet_ids)}"]
tag {
key = "Name"
value = "app${count.index}"
propagate_at_launch = true
}
}
resource "aws_launch_configuration" "lc_app" {
lifecycle { create_before_destroy = true }
image_id = "${var.ami}"
instance_type = "t2.micro"
security_groups = ["${module.network.sg_default}", "${aws_security_group.app.id}"]
user_data = "${file("user_data/app-server.sh")}"
}