-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
108 lines (100 loc) · 4.65 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#------------------------------------------------------------------------------
# AWS ECS Task Execution Role
#------------------------------------------------------------------------------
resource "aws_iam_role" "ecs_task_execution_role" {
name = "${var.name_preffix}-ecs-task-execution-role"
assume_role_policy = file("${path.module}/files/iam/ecs_task_execution_iam_role.json")
}
resource "aws_iam_role_policy_attachment" "ecs_task_execution_role_policy_attach" {
role = aws_iam_role.ecs_task_execution_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}
#------------------------------------------------------------------------------
# ECS Task Definition
#------------------------------------------------------------------------------
# Container Definition
module "container_definition" {
source = "cloudposse/ecs-container-definition/aws"
version = "0.23.0"
container_name = var.container_name
container_image = var.container_image
container_memory = var.container_memory
container_memory_reservation = var.container_memory_reservation
port_mappings = var.port_mappings
healthcheck = var.healthcheck
container_cpu = var.container_cpu
essential = var.essential
entrypoint = var.entrypoint
command = var.command
working_directory = var.working_directory
environment = var.environment
secrets = var.secrets
readonly_root_filesystem = var.readonly_root_filesystem
linux_parameters = var.linux_parameters
log_configuration = var.log_configuration
firelens_configuration = var.firelens_configuration
mount_points = var.mount_points
dns_servers = var.dns_servers
ulimits = var.ulimits
docker_labels = var.docker_labels
repository_credentials = var.repository_credentials
volumes_from = var.volumes_from
links = var.links
user = var.user
container_depends_on = var.container_depends_on
start_timeout = var.start_timeout
stop_timeout = var.stop_timeout
system_controls = var.system_controls
}
# Task Definition
resource "aws_ecs_task_definition" "td" {
family = "${var.name_preffix}-td"
container_definitions = "[ ${module.container_definition.json_map} ]"
task_role_arn = var.task_role_arn == null ? aws_iam_role.ecs_task_execution_role.arn : var.task_role_arn
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
network_mode = "awsvpc"
dynamic "placement_constraints" {
for_each = var.placement_constraints
content {
expression = lookup(placement_constraints.value, "expression", null)
type = placement_constraints.value.type
}
}
cpu = var.container_cpu
memory = var.container_memory
requires_compatibilities = ["FARGATE"]
dynamic "proxy_configuration" {
for_each = var.proxy_configuration
content {
container_name = proxy_configuration.value.container_name
properties = lookup(proxy_configuration.value, "properties", null)
type = lookup(proxy_configuration.value, "type", null)
}
}
dynamic "volume" {
for_each = var.volumes
content {
name = volume.value.name
host_path = lookup(volume.value, "host_path", null)
dynamic "docker_volume_configuration" {
for_each = lookup(volume.value, "docker_volume_configuration", [])
content {
autoprovision = lookup(docker_volume_configuration.value, "autoprovision", null)
driver = lookup(docker_volume_configuration.value, "driver", null)
driver_opts = lookup(docker_volume_configuration.value, "driver_opts", null)
labels = lookup(docker_volume_configuration.value, "labels", null)
scope = lookup(docker_volume_configuration.value, "scope", null)
}
}
dynamic "efs_volume_configuration" {
for_each = lookup(volume.value, "efs_volume_configuration", [])
content {
file_system_id = lookup(efs_volume_configuration.value, "file_system_id", null)
root_directory = lookup(efs_volume_configuration.value, "root_directory", null)
}
}
}
}
}
# TODO - Add this missing parameter
# inference_accelerator - (Optional) Configuration block(s) with Inference Accelerators settings. Detailed below.