-
Notifications
You must be signed in to change notification settings - Fork 63
/
infrostructure.tf
59 lines (51 loc) · 1.25 KB
/
infrostructure.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
#### INSTANCE HTTP ####
resource "aws_lb" "front_end" {
# ...
}
resource "aws_lb_target_group" "front_end" {
# ...
}
resource "aws_lb_listener" "front_end" {
load_balancer_arn = aws_lb.front_end.arn
port = "80"
protocol = "HTTP"
default_action {
type = "redirect"
redirect {
port = "80"
protocol = "HTTP"
status_code = "HTTP_301"
}
}
}
resource "aws_alb_listener" "front_end" {
load_balancer_arn = aws_lb.front_end.arn
port = "8080"
protocol = "HTTP"
}
# Create instance
resource "aws_instance" "http" {
for_each = var.http_instance_names
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
key_name = aws_key_pair.user_key.key_name
vpc_security_group_ids = [
aws_security_group.administration.id,
aws_security_group.web.id,
]
subnet_id = aws_subnet.http.id
user_data = "1234567890123456789012345678901234567890$"
tags = {
Name = each.key
}
}
# Attach floating ip on instance http
resource "aws_eip" "public_http" {
for_each = var.http_instance_names
vpc = true
instance = aws_instance.http[each.key].id
depends_on = [aws_internet_gateway.gw]
tags = {
Name = "public-http-${each.key}"
}
}