This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathec2.tf
106 lines (90 loc) · 2.45 KB
/
ec2.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
104
105
106
resource "aws_security_group" "hello_instance_sg" {
name = "hello-instance-sg"
description = "SG applied to each hello-world instances"
vpc_id = "${aws_vpc.default.id}"
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "hello_elb_sg" {
name = "hello-elb-sg"
description = "SG applied to the hello-world elastic load balancer"
vpc_id = "${aws_vpc.default.id}"
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_launch_configuration" "hello_as_conf" {
name = "hello-as-launch-config-${var.timestamp}"
image_id = "${lookup(var.aws_amis, var.aws_region)}"
instance_type = "t2.micro"
key_name = "${var.aws_key_name}"
security_groups = ["${aws_security_group.hello_instance_sg.id}"]
associate_public_ip_address = true
user_data = "${file(\"ec2_bootstrap.sh\")}"
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "hello_as" {
availability_zones = ["eu-west-1a", "eu-west-1b"]
vpc_zone_identifier = ["${aws_subnet.eu-west-1a-private.id}", "${aws_subnet.eu-west-1b-private.id}"]
name = "hello-autoscaling-group-${var.timestamp}"
min_size = "${var.asg_min_size}"
max_size = "${var.asg_max_size}"
desired_capacity = "${var.asg_desired_capacity}"
health_check_grace_period = 300
health_check_type = "ELB"
force_delete = true
launch_configuration = "${aws_launch_configuration.hello_as_conf.id}"
load_balancers = ["${aws_elb.hello-elb.name}"]
tag {
key = "Name"
value = "hello_web"
propagate_at_launch = true
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_elb" "hello-elb" {
name = "hello-elb"
subnets = ["${aws_subnet.eu-west-1a-public.id}", "${aws_subnet.eu-west-1b-public.id}"]
security_groups = ["${aws_security_group.hello_elb_sg.id}"]
internal = false
cross_zone_load_balancing = true
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 8080
lb_protocol = "http"
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
target = "HTTP:80/"
interval = 5
}
lifecycle {
create_before_destroy = true
}
}