-
Notifications
You must be signed in to change notification settings - Fork 8
/
service_apigo.tf
132 lines (118 loc) · 3.22 KB
/
service_apigo.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
resource "aws_ecs_task_definition" "api-go-TD" {
family = "api-go-TD"
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
cpu = 2048
memory = 4096
execution_role_arn = data.aws_iam_role.ecs_task_execution_role.arn
container_definitions = jsonencode([
{
name = "container-name"
image = "nginx" //bunu düzelticem
cpu = 2048
memory = 4096
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-create-group = "true"
awslogs-group = "/ecs/api-go"
awslogs-region = var.region
awslogs-stream-prefix = "ecs"
}
}
essential = true
portMappings = [
{
containerPort = 80
hostPort = 80
}
]
}
])
}
resource "aws_lb_target_group" "api-go-tg" {
name = "api-go-tg"
port = 80
protocol = "HTTP"
target_type = "ip"
vpc_id = aws_vpc.vpc.id
health_check {
enabled = true
path = "/healthcheck"
port = 80
protocol = "HTTP"
healthy_threshold = 2
unhealthy_threshold = 3
timeout = 5
interval = 10
}
tags = {
Name = "api-go-tg"
Environment = var.environment
}
}
resource "aws_ecs_service" "api-go-service" {
name = "api-go-service"
cluster = aws_ecs_cluster.base-cluster.id
task_definition = aws_ecs_task_definition.api-go-TD.id
desired_count = 20
depends_on = [
aws_ecs_cluster.base-cluster,
aws_ecs_task_definition.api-go-TD,
aws_lb_target_group.api-go-tg,
]
launch_type = "FARGATE"
network_configuration {
subnets = [aws_subnet.private-subnet-a.id, aws_subnet.private-subnet-b.id]
security_groups = [aws_security_group.service-sg.id]
assign_public_ip = true
}
load_balancer {
target_group_arn = aws_lb_target_group.api-go-tg.arn
container_name = "container-name"
container_port = 80
}
lifecycle {
ignore_changes = [task_definition]
}
}
resource "aws_lb_listener_rule" "api-go-rule" {
listener_arn = aws_lb_listener.backend-go-alb-listener.arn
priority = 100
action {
type = "forward"
target_group_arn = aws_lb_target_group.api-go-tg.arn
}
condition {
path_pattern {
values = ["*"]
}
}
}
resource "aws_lb" "backend-go-alb" {
name = "backend-go-alb"
internal = false
load_balancer_type = "application"
security_groups = ["sg-09d6376212dfa6ea1"] // Todo change
subnets = [aws_subnet.public-subnet-a.id, aws_subnet.public-subnet-b.id]
enable_deletion_protection = true
tags = {
Name = "backend-go-alb"
}
}
resource "aws_wafv2_web_acl_association" "backend-go-alb" {
resource_arn = aws_lb.backend-go-alb.arn
web_acl_arn = aws_wafv2_web_acl.generic.arn
}
resource "aws_lb_listener" "backend-go-alb-listener" {
load_balancer_arn = aws_lb.backend-go-alb.arn
port = "80"
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.api-go-tg.arn
}
depends_on = [
aws_lb.backend-go-alb
]
}