-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
59 lines (54 loc) · 2.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
57
58
59
locals {
# Sort environment variables so terraform will not try to recreate on each plan/apply
env_vars = var.environment != null ? var.environment : []
env_vars_keys = [for m in local.env_vars : lookup(m, "name")]
env_vars_values = [for m in local.env_vars : lookup(m, "value")]
env_vars_as_map = zipmap(local.env_vars_keys, local.env_vars_values)
sorted_env_vars_keys = sort(local.env_vars_keys)
sorted_environment_vars = [
for key in local.sorted_env_vars_keys :
{
name = key
value = lookup(local.env_vars_as_map, key)
}
]
# This strange-looking variable is needed because terraform (currently) does not support explicit `null` in ternary operator,
# so this does not work: final_environment_vars = length(local.sorted_environment_vars) > 0 ? local.sorted_environment_vars : null
null_value = var.environment == null ? var.environment : null
# https://www.terraform.io/docs/configuration/expressions.html#null
final_environment_vars = length(local.sorted_environment_vars) > 0 ? local.sorted_environment_vars : local.null_value
container_definition = {
name = var.container_name
image = var.container_image
essential = var.essential
entryPoint = var.entrypoint
command = var.command
workingDirectory = var.working_directory
readonlyRootFilesystem = var.readonly_root_filesystem
mountPoints = var.mount_points
dnsServers = var.dns_servers
ulimits = var.ulimits
repositoryCredentials = var.repository_credentials
links = var.links
volumesFrom = var.volumes_from
user = var.user
dependsOn = var.container_depends_on
privileged = var.privileged
portMappings = var.port_mappings
healthCheck = var.healthcheck
firelensConfiguration = var.firelens_configuration
linuxParameters = var.linux_parameters
logConfiguration = var.log_configuration
memory = var.container_memory
memoryReservation = var.container_memory_reservation
cpu = var.container_cpu
environment = local.final_environment_vars
environmentFiles = var.environment_files
secrets = var.secrets
dockerLabels = var.docker_labels
startTimeout = var.start_timeout
stopTimeout = var.stop_timeout
systemControls = var.system_controls
}
json_map = jsonencode(local.container_definition)
}