-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
74 lines (65 loc) · 1.82 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
provider "aws" {
profile = "qiross"
region = "us-east-1"
}
resource "aws_ecs_cluster" "fastapi_cluster" {
name = "fastapi-fargate-cluster"
}
resource "aws_iam_role" "ecs_task_execution_role" {
name = "ecsTaskExecutionRole"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "ecs-tasks.amazonaws.com"
}
Effect = "Allow"
Sid = ""
},
]
})
}
resource "aws_iam_role_policy_attachment" "ecs_task_execution_role_policy" {
role = aws_iam_role.ecs_task_execution_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}
resource "aws_ecs_task_definition" "fastapi_task" {
family = "fastapi-fargate-task"
container_definitions = jsonencode([
{
name = "fastapi-container"
image = "qiross/fastapi-fargate:latest"
cpu = 256
memory = 512
essential = true
portMappings = [
{
containerPort = 80
hostPort = 80
}
]
}
])
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
cpu = "256"
memory = "512"
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
}
resource "aws_ecs_service" "fastapi_service" {
name = "fastapi-fargate-service"
cluster = aws_ecs_cluster.fastapi_cluster.id
task_definition = aws_ecs_task_definition.fastapi_task.arn
desired_count = 1
capacity_provider_strategy {
capacity_provider = "FARGATE_SPOT"
weight = 1
}
network_configuration {
subnets = ["subnet-01fb57be965f0ab32"]
security_groups = ["sg-06b1d2e2e843529f4"]
assign_public_ip = true
}
}