-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecs.tf
86 lines (77 loc) · 1.96 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
resource "aws_ecs_cluster" "taskoverflow" {
name = "taskoverflow"
}
resource "aws_ecs_task_definition" "todo" {
family = "todo"
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = 1024
memory = 2048
execution_role_arn = data.aws_iam_role.lab.arn
container_definitions = <<DEFINITION
[
{
"image": "${local.image}",
"cpu": 1024,
"memory": 2048,
"name": "todo",
"networkMode": "awsvpc",
"portMappings": [
{
"containerPort": 6400,
"hostPort": 6400
}
],
"environment": [
{
"name": "SQLALCHEMY_DATABASE_URI",
"value": "postgresql://${local.database_username}:${local.database_password}@${aws_db_instance.database.address}:${aws_db_instance.database.port}/${aws_db_instance.database.db_name}"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/taskoverflow/todo",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs",
"awslogs-create-group": "true"
}
}
}
]
DEFINITION
}
resource "aws_ecs_service" "taskoverflow" {
name = "taskoverflow"
cluster = aws_ecs_cluster.taskoverflow.id
task_definition = aws_ecs_task_definition.todo.arn
desired_count = 1
launch_type = "FARGATE"
network_configuration {
subnets = data.aws_subnets.private.ids
security_groups = [aws_security_group.todo.id]
assign_public_ip = true
}
}
resource "aws_security_group" "todo" {
name = "todo"
description = "TaskOverflow Security Group"
ingress {
from_port = 6400
to_port = 6400
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}