-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathecs.tf
62 lines (59 loc) · 1.82 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
resource "aws_ecs_cluster" "tfc_agent" {
name = "${var.name}Cluster"
capacity_providers = var.capacity_providers
tags = var.common_tags
}
resource "aws_ecs_service" "tfc_agent" {
name = "${var.name}Service"
cluster = aws_ecs_cluster.tfc_agent.id
launch_type = "FARGATE"
desired_count = var.num_agents
task_definition = aws_ecs_task_definition.tfc_agent.arn
tags = var.common_tags
network_configuration {
security_groups = local.security_groups
subnets = local.subnets
assign_public_ip = false
}
}
resource "aws_ecs_task_definition" "tfc_agent" {
family = "${var.name}Task"
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
container_definitions = local.agent_task_definition
execution_role_arn = aws_iam_role.init.arn
task_role_arn = aws_iam_role.runtime.arn
cpu = local.cpu
memory = local.memory
tags = var.common_tags
}
locals {
agent_task_definition = jsonencode([
{
name = "tfc-agent"
image = var.tfc_agent_image
essential = true
cpu = local.cpu
memory = local.memory
environment = concat([{
name = "TFC_AGENT_NAME"
value = "${var.name}-ecs"
}], var.tfc_agent_env_vars)
secrets = [
{
name = "TFC_AGENT_TOKEN"
valueFrom = local.tfc_agent_token_parameter_arn
}
]
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-create-group = "true"
awslogs-group = local.cloudwatch_log_group
awslogs-region = data.aws_region.current.name
awslogs-stream-prefix = "logs"
}
}
}
])
}