-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathec2.tf
85 lines (69 loc) · 1.74 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
resource "aws_launch_template" "ecs_lt" {
name_prefix = "ecs-template"
image_id = "ami-062c116e449466e7f"
instance_type = "t3.micro"
key_name = "ec2ecsglog"
vpc_security_group_ids = [aws_security_group.security_group.id]
iam_instance_profile {
name = "ecsInstanceRole"
}
block_device_mappings {
device_name = "/dev/xvda"
ebs {
volume_size = 30
volume_type = "gp2"
}
}
tag_specifications {
resource_type = "instance"
tags = {
Name = "ecs-instance"
}
}
user_data = filebase64("${path.module}/ecs.sh")
}
resource "aws_autoscaling_group" "ecs_asg" {
vpc_zone_identifier = [aws_subnet.subnet.id, aws_subnet.subnet2.id]
desired_capacity = 2
max_size = 3
min_size = 1
launch_template {
id = aws_launch_template.ecs_lt.id
version = "$Latest"
}
tag {
key = "AmazonECSManaged"
value = true
propagate_at_launch = true
}
}
//Alb
resource "aws_lb" "ecs_alb" {
name = "ecs-alb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.security_group.id]
subnets = [aws_subnet.subnet.id, aws_subnet.subnet2.id]
tags = {
Name = "ecs-alb"
}
}
resource "aws_lb_listener" "ecs_alb_listener" {
load_balancer_arn = aws_lb.ecs_alb.arn
port = 80
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.ecs_tg.arn
}
}
resource "aws_lb_target_group" "ecs_tg" {
name = "ecs-target-group"
port = 80
protocol = "HTTP"
target_type = "ip"
vpc_id = aws_vpc.main.id
health_check {
path = "/"
}
}