-
Notifications
You must be signed in to change notification settings - Fork 3
/
services.tf
68 lines (59 loc) · 1.72 KB
/
services.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
data "aws_region" "this" {}
data "template_file" "container_definitions" {
template = file("${path.module}/container-definitions.tmpl")
vars = {
name = var.name
image = var.image
cpu = var.cpu
memory = var.memory
volume_name = var.name
volume_path = "/data/db"
environment = jsonencode(var.environment)
cloudwatch = var.cloudwatch
logs_group = var.name
logs_stream_prefix = var.name
logs_region = data.aws_region.this.name
}
}
resource "aws_ecs_task_definition" "this" {
family = var.name
container_definitions = data.template_file.container_definitions.rendered
execution_role_arn = aws_iam_role.this.arn
cpu = var.cpu
memory = var.memory
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
dynamic "volume" {
for_each = var.volume_type == "efs" ? [1] : []
content {
name = var.name
efs_volume_configuration {
file_system_id = aws_efs_file_system.this[0].id
}
}
}
dynamic "volume" {
for_each = var.volume_type == "ebs" ? [1] : []
content {
name = var.name
}
}
}
resource "aws_ecs_service" "this" {
name = var.name
cluster = var.cluster
launch_type = "FARGATE"
platform_version = "1.4.0"
task_definition = aws_ecs_task_definition.this.arn
desired_count = 1
network_configuration {
assign_public_ip = true
security_groups = [aws_security_group.this.id]
subnets = var.subnets
}
load_balancer {
target_group_arn = aws_lb_target_group.this.arn
container_name = var.name
container_port = 27017
}
}