-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecs.tf
111 lines (107 loc) · 2.61 KB
/
ecs.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
# Create ECS Cluster
resource "aws_ecs_cluster" "ecs_cluster" {
name = "Final-challenge-cluster"
}
# Create ECS task definition
resource "aws_ecs_task_definition" "task_definition" {
family = "worker"
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
task_role_arn = aws_iam_role.ecs_task_role.arn
container_definitions = jsonencode([
{
name = "worker",
image = "", #image
cpu = 10
memory = 512
essential = true
environment = [
{
"name" : "APP_NAME",
"value" : "Laravel"
},
{
"name" : "APP_ENV",
"value" : "local"
},
{
"name" : "APP_KEY",
"value" : "base64:+/FQNhtSP2dDuCuQReSF3pcz1ztJi29qchU7zThGA8c="
},
{
"name" : "APP_DEBUG",
"value" : "true"
},
{
"name" : "APP_LOG_LEVEL",
"value" : "debug"
},
{
"name" : "APP_URL",
"value" : "http://localhost"
},
{
"name" : "DB_CONNECTION",
"value" : "mysql"
},
{
"name" : "DB_HOST",
"value" : "terraform-20220316031006412800000003.c2um9xuvwycx.ap-southeast-2.rds.amazonaws.com" #RDS endpoint
},
{
"name" : "DB_PORT",
"value" : "3306"
},
{
"name" : "DB_DATABASE",
"value" : "mydb"
},
{
"name" : "DB_USERNAME",
"value" : "user1"
},
{
"name" : "DB_PASSWORD",
"value" : "password"
},
{
"name" : "BROADCAST_DRIVER",
"value" : "log"
},
{
"name" : "CACHE_DRIVER",
"value" : "file"
},
{
"name" : "SESSION_DRIVER",
"value" : "file"
},
{
"name" : "QUEUE_DRIVER",
"value" : "sync"
},
{
"name" : "CORS_ALLOWED_ORIGINS",
"value" : "http://localhost:3000,http://localhost:4200"
},
]
portMappings = [{
protocol = "tcp"
containerPort = 80
hostPort = 80
}]
}
])
}
# Create ECS service
resource "aws_ecs_service" "worker" {
name = "worker"
cluster = aws_ecs_cluster.ecs_cluster.id
task_definition = aws_ecs_task_definition.task_definition.arn
desired_count = 2
launch_type = "EC2"
load_balancer {
target_group_arn = aws_lb_target_group.final-challenge-target-group.arn
container_name = "worker"
container_port = 80
}
}