-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
56 lines (48 loc) · 1.63 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
locals {
tags = var.tags
}
resource "aws_ecs_cluster" "default" {
name = "${var.app_name}-cluster"
tags = local.tags
}
data "template_file" "default" {
template = file("./templates/image/image.tf.json")
vars = {
app_image = var.app_image
app_port = var.app_port
fargate_cpu = var.fargate_cpu
fargate_memory = var.fargate_memory
aws_region = var.aws_region
redis_host = var.redis_host
app_name = var.app_name
}
}
resource "aws_ecs_task_definition" "default" {
family = "${var.app_name}-task"
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = var.fargate_cpu
memory = var.fargate_memory
container_definitions = data.template_file.default.rendered
tags = local.tags
}
resource "aws_ecs_service" "default" {
name = "${var.app_name}-service"
cluster = aws_ecs_cluster.default.id
task_definition = aws_ecs_task_definition.default.arn
desired_count = var.app_count
launch_type = "FARGATE"
network_configuration {
security_groups = [aws_security_group.ecs_sg.id]
subnets = var.subnet_ids
assign_public_ip = true
}
load_balancer {
target_group_arn = aws_alb_target_group.default.arn
container_name = var.app_name
container_port = var.app_port
}
tags = local.tags
depends_on = [aws_alb_listener.default, aws_iam_role_policy_attachment.ecs_task_execution_role]
}