-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
97 lines (79 loc) · 2.21 KB
/
main.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
### Target Groups ###
resource "aws_lb_target_group" "main" {
name = var.main_target_group_name
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
target_type = "ip"
deregistration_delay = 5
health_check {
protocol = "HTTP"
path = "/v1/health"
matcher = "200"
timeout = "3"
interval = "30"
healthy_threshold = "2"
unhealthy_threshold = "2"
}
tags = {
Name = var.main_target_group_name
}
}
### ECS Service ###
resource "aws_security_group" "ecs_sg" {
name_prefix = var.security_group_name_prefix
vpc_id = var.vpc_id
ingress {
protocol = "tcp"
from_port = 3000
to_port = 3000
self = "false"
cidr_blocks = var.public_subnet_cidrs
}
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
tags = {
Name = var.security_group_name
}
}
resource "aws_ecs_cluster" "main" {
name = var.cluster_name
tags = {
Name = var.cluster_name
}
}
resource "aws_ecs_service" "electric_sync" {
name = var.service_name
cluster = aws_ecs_cluster.main.id
task_definition = var.task_definition.arn
desired_count = 1
launch_type = "FARGATE"
health_check_grace_period_seconds = 60
deployment_minimum_healthy_percent = 0
deployment_maximum_percent = 100
network_configuration {
security_groups = [aws_security_group.ecs_sg.id]
subnets = var.public_subnet_ids
# This is required for Fargate tasks launched by this service to be able to
# pull a Docker image from ECR or Docker Hub.
assign_public_ip = true
}
load_balancer {
target_group_arn = aws_lb_target_group.main.id
container_name = var.task_container_name
container_port = 3000
}
# This is needed to keep terraform from falling into an infinite loop when the task fails to
# start and is automatically recreated by AWS.
lifecycle {
ignore_changes = [desired_count]
}
tags = {
Name = var.service_name
}
}