1
+ # TODO: Remove after release
1
2
resource "aws_security_group" "ecs_service_sg" {
2
3
name = " ecs-service-sg"
3
4
description = " Security Group for communication with ECS"
@@ -7,6 +8,7 @@ resource "aws_security_group" "ecs_service_sg" {
7
8
}
8
9
}
9
10
11
+ # TODO: Remove after release
10
12
resource "aws_security_group_rule" "ecs_ingress_http" {
11
13
type = " ingress"
12
14
from_port = 4000
@@ -19,6 +21,7 @@ resource "aws_security_group_rule" "ecs_ingress_http" {
19
21
}
20
22
}
21
23
24
+ # TODO: Remove after release
22
25
resource "aws_security_group_rule" "ecs_talk_to_internet" {
23
26
type = " egress"
24
27
from_port = 0
@@ -28,15 +31,7 @@ resource "aws_security_group_rule" "ecs_talk_to_internet" {
28
31
security_group_id = aws_security_group. ecs_service_sg . id
29
32
}
30
33
31
- resource "aws_ecs_cluster" "cluster" {
32
- name = " mavis-${ var . environment } "
33
-
34
- setting {
35
- name = " containerInsights"
36
- value = " enabled"
37
- }
38
- }
39
-
34
+ # TODO: Remove after release
40
35
resource "aws_ecs_service" "service" {
41
36
name = " mavis-${ var . environment } "
42
37
cluster = aws_ecs_cluster. cluster . id
@@ -53,7 +48,7 @@ resource "aws_ecs_service" "service" {
53
48
54
49
load_balancer {
55
50
target_group_arn = aws_lb_target_group. blue . arn
56
- container_name = local . container_name
51
+ container_name = " mavis- ${ var . environment } "
57
52
container_port = 4000
58
53
}
59
54
deployment_controller {
@@ -69,6 +64,7 @@ resource "aws_ecs_service" "service" {
69
64
}
70
65
}
71
66
67
+ # TODO: Remove after release
72
68
resource "aws_ecs_task_definition" "task_definition" {
73
69
family = " task-definition-${ var . environment } "
74
70
requires_compatibilities = [" FARGATE" ]
@@ -79,7 +75,7 @@ resource "aws_ecs_task_definition" "task_definition" {
79
75
task_role_arn = aws_iam_role. ecs_task_role . arn
80
76
container_definitions = jsonencode ([
81
77
{
82
- name = local.container_name
78
+ name = " mavis- ${ var . environment } "
83
79
image = " ${ var . account_id } .dkr.ecr.eu-west-2.amazonaws.com/${ var . docker_image } @${ var . image_digest } "
84
80
essential = true
85
81
portMappings = [
@@ -88,7 +84,7 @@ resource "aws_ecs_task_definition" "task_definition" {
88
84
hostPort = 4000
89
85
}
90
86
]
91
- environment = local.task_envs
87
+ environment = concat ( local. task_envs , [{ name = " SERVER_TYPE " , value = " web " }])
92
88
secrets = local.task_secrets
93
89
logConfiguration = {
94
90
logDriver = " awslogs"
@@ -109,3 +105,77 @@ resource "aws_ecs_task_definition" "task_definition" {
109
105
])
110
106
depends_on = [aws_cloudwatch_log_group . ecs_log_group ]
111
107
}
108
+
109
+ resource "aws_security_group_rule" "web_service_alb_ingress" {
110
+ type = " ingress"
111
+ from_port = 4000
112
+ to_port = 4000
113
+ protocol = " tcp"
114
+ security_group_id = module. web_service . security_group_id
115
+ source_security_group_id = aws_security_group. lb_service_sg . id
116
+ lifecycle {
117
+ create_before_destroy = true
118
+ }
119
+ }
120
+
121
+ resource "aws_ecs_cluster" "cluster" {
122
+ name = " mavis-${ var . environment } "
123
+
124
+ setting {
125
+ name = " containerInsights"
126
+ value = " enabled"
127
+ }
128
+ }
129
+
130
+ module "web_service" {
131
+ source = " ./modules/ecs_service"
132
+ task_config = {
133
+ environment = local.task_envs
134
+ secrets = local.task_secrets
135
+ cpu = 1024
136
+ memory = 2048
137
+ docker_image = " ${ var . account_id } .dkr.ecr.eu-west-2.amazonaws.com/${ var . docker_image } @${ var . image_digest } "
138
+ execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
139
+ task_role_arn = aws_iam_role.ecs_task_role.arn
140
+ log_group_name = aws_cloudwatch_log_group.ecs_log_group.name
141
+ region = var.region
142
+ health_check_command = [" CMD-SHELL" , " curl -f http://localhost:4000/up || exit 1" ]
143
+ }
144
+ network_params = {
145
+ subnets = [aws_subnet.private_subnet_a.id, aws_subnet.private_subnet_b.id]
146
+ vpc_id = aws_vpc.application_vpc.id
147
+ }
148
+ loadbalancer = {
149
+ target_group_arn = aws_lb_target_group.green.arn
150
+ container_port = 4000
151
+ }
152
+ cluster_id = aws_ecs_cluster. cluster . id
153
+ environment = var. environment
154
+ server_type = " web"
155
+ desired_count = var. minimum_replicas
156
+ deployment_controller = " CODE_DEPLOY"
157
+ }
158
+
159
+ module "good_job_service" {
160
+ source = " ./modules/ecs_service"
161
+ task_config = {
162
+ environment = local.task_envs
163
+ secrets = local.task_secrets
164
+ cpu = 1024
165
+ memory = 2048
166
+ docker_image = " ${ var . account_id } .dkr.ecr.eu-west-2.amazonaws.com/${ var . docker_image } @${ var . image_digest } "
167
+ execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
168
+ task_role_arn = aws_iam_role.ecs_task_role.arn
169
+ log_group_name = aws_cloudwatch_log_group.ecs_log_group.name
170
+ region = var.region
171
+ health_check_command = [" CMD-SHELL" , " curl -f http://localhost:4000 || exit 1" ]
172
+ }
173
+ network_params = {
174
+ subnets = [aws_subnet.private_subnet_a.id, aws_subnet.private_subnet_b.id]
175
+ vpc_id = aws_vpc.application_vpc.id
176
+ }
177
+ cluster_id = aws_ecs_cluster. cluster . id
178
+ environment = var. environment
179
+ server_type = " good-job"
180
+ desired_count = 1
181
+ }
0 commit comments