-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample-asg.tf
103 lines (90 loc) · 2.25 KB
/
sample-asg.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
resource "aws_security_group" "instance_sg" {
name = "Allow ELB access to instance"
vpc_id = "${aws_vpc.vpc.id}"
ingress {
from_port = 8080
protocol = "tcp"
to_port = 8080
security_groups = ["${aws_security_group.elb_sg.id}"]
}
egress {
from_port = 0
protocol = "-1"
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags {
Name = "${var.team_name}-yocto-instance-sg"
}
}
resource "aws_security_group" "elb_sg" {
name = "Allow public access via http"
vpc_id = "${aws_vpc.vpc.id}"
ingress {
from_port = 80
protocol = "tcp"
to_port = 80
cidr_blocks = [
"0.0.0.0/0"]
}
egress {
from_port = 0
protocol = "-1"
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags {
Name = "${var.team_name}-yocto-elb-sg"
}
}
data "template_file" "yocto_userdata" {
template = "${file("${path.module}/templates/yocto-userdata.tpl")}"
}
resource "aws_launch_configuration" "yocto_lc" {
name_prefix = "${var.team_name}-"
image_id = "${var.ami_id}"
instance_type = "${var.instance_type}"
key_name = "${var.sshkeyname}"
user_data = "${data.template_file.yocto_userdata.rendered}"
security_groups = ["${aws_security_group.instance_sg.id}"]
associate_public_ip_address = true
lifecycle { create_before_destroy = true }
}
resource "aws_autoscaling_group" "asg" {
name_prefix = "${var.team_name}-"
launch_configuration = "${aws_launch_configuration.yocto_lc.id}"
max_size = 2
min_size = 1
desired_capacity = 1
vpc_zone_identifier = ["${aws_subnet.public_subnets.*.id}"]
load_balancers = ["${aws_elb.elb.id}"]
health_check_type = "ELB"
health_check_grace_period = 120
wait_for_capacity_timeout = "3m"
lifecycle {create_before_destroy = true}
tags = [
{
key = "Name"
value = "${var.team_name}-yocto"
propagate_at_launch = true
}
]
}
resource "aws_elb" "elb" {
name = "${var.team_name}-yocto-elb"
subnets = ["${aws_subnet.public_subnets.*.id}"]
security_groups = ["${aws_security_group.elb_sg.id}"]
listener {
instance_port = 8080
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
health_check {
healthy_threshold = 2
interval = 5
target = "HTTP:8080/status"
timeout = 2
unhealthy_threshold = 2
}
}