-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.tf
More file actions
76 lines (63 loc) · 2.55 KB
/
main.tf
File metadata and controls
76 lines (63 loc) · 2.55 KB
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
locals {
family = "${var.project}-${var.environment}-${var.task}"
container = var.container != null ? var.container : var.task
image_tag = var.image_tag != null ? var.image_tag : join("", data.aws_ecs_container_definition.current.*.image_digest)
image = var.image != null ? var.image : "${var.image_name}:${local.image_tag}"
}
module "container_log" {
source = "./log_group"
create = var.create
project = var.project
environment = var.environment
task = var.task
container = var.container
tags = var.tags
retention = var.log_retention
}
data "aws_ecs_container_definition" "current" {
count = var.create && var.image == null && var.image_tag == null ? 1 : 0
task_definition = local.family
container_name = local.container
}
module "container" {
source = "./container_definition"
create = var.create
name = local.container
image = local.image
memory_hard_limit = var.memory_hard_limit
memory_soft_limit = var.memory_soft_limit
ports = var.ports
cpu = var.cpu
essential = var.essential
entry_point = var.entry_point
command = var.command
working_directory = var.working_directory
environment_variables = var.environment_variables
environment_parameters = var.environment_parameters
enable_environment_parameters_hash = var.enable_environment_parameters_hash
log_config = module.container_log.container_config
healthcheck_command = var.healthcheck_command
healthcheck_shell = var.healthcheck_shell
healthcheck_interval = var.healthcheck_interval
healthcheck_retries = var.healthcheck_retries
healthcheck_start_period = var.healthcheck_start_period
healthcheck_timeout = var.healthcheck_timeout
}
resource "aws_ecs_task_definition" "task" {
count = var.create ? 1 : 0
family = local.family
container_definitions = jsonencode([module.container.definition])
task_role_arn = var.role_arn
execution_role_arn = var.execution_role_arn
cpu = var.task_cpu
memory = var.task_memory
network_mode = var.network_mode
dynamic "placement_constraints" {
for_each = var.placement_constraint_expressions
iterator = expression
content {
expression = expression.value
type = "memberOf"
}
}
}