Skip to content

Commit dcc8d08

Browse files
committed
fix: remove template_file resource
1 parent 5fb903f commit dcc8d08

File tree

2 files changed

+42
-43
lines changed

2 files changed

+42
-43
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
output "container_definitions" {
2-
value = "${module.merged.container_definitions}"
2+
value = module.merged.container_definitions
33
}

Diff for: main.tf

+41-42
Original file line numberDiff line numberDiff line change
@@ -82,50 +82,49 @@ locals {
8282
digit = "/\"(-[[:digit:]]|[[:digit:]]+)\"/"
8383
}
8484

85-
container_definition = var.register_task_definition ? format("[%s]", data.template_file.container_definition.rendered) : format("%s", data.template_file.container_definition.rendered)
85+
template_file = templatefile(
86+
"${path.module}/templates/container-definition.json.tpl",
87+
{
88+
command = local.command == "[]" ? "null" : local.command
89+
cpu = var.cpu == 0 ? "null" : var.cpu
90+
disableNetworking = var.disableNetworking ? true : false
91+
dnsSearchDomains = local.dnsSearchDomains == "[]" ? "null" : local.dnsSearchDomains
92+
dnsServers = local.dnsServers == "[]" ? "null" : local.dnsServers
93+
dockerLabels = local.dockerLabels == "{}" ? "null" : local.dockerLabels
94+
dockerSecurityOptions = local.dockerSecurityOptions == "[]" ? "null" : local.dockerSecurityOptions
95+
entryPoint = local.entryPoint == "[]" ? "null" : local.entryPoint
96+
environment = local.environment == "[]" ? "null" : local.environment
97+
essential = var.essential ? true : false
98+
extraHosts = local.extraHosts == "[]" ? "null" : local.extraHosts
99+
healthCheck = local.healthCheck == "{}" ? "null" : local.healthCheck
100+
hostname = var.hostname == "" ? "null" : var.hostname
101+
image = var.image == "" ? "null" : var.image
102+
interactive = var.interactive ? true : false
103+
links = local.links == "[]" ? "null" : local.links
104+
linuxParameters = local.linuxParameters == "{}" ? "null" : local.linuxParameters
105+
logConfiguration = local.logConfiguration == "{}" ? "null" : local.logConfiguration
106+
memory = var.memory == 0 ? "null" : var.memory
107+
memoryReservation = var.memoryReservation == 0 ? "null" : var.memoryReservation
108+
mountPoints = local.mountPoints == "[]" ? "null" : local.mountPoints
109+
name = var.name == "" ? "null" : var.name
110+
portMappings = local.portMappings == "[]" ? "null" : local.portMappings
111+
privileged = var.privileged ? true : false
112+
pseudoTerminal = var.pseudoTerminal ? true : false
113+
readonlyRootFilesystem = var.readonlyRootFilesystem ? true : false
114+
repositoryCredentials = local.repositoryCredentials == "{}" ? "null" : local.repositoryCredentials
115+
resourceRequirements = local.resourceRequirements == "[]" ? "null" : local.resourceRequirements
116+
secrets = local.secrets == "[]" ? "null" : local.secrets
117+
systemControls = local.systemControls == "[]" ? "null" : local.systemControls
118+
ulimits = local.ulimits == "[]" ? "null" : local.ulimits
119+
user = var.user == "" ? "null" : var.user
120+
volumesFrom = local.volumesFrom == "[]" ? "null" : local.volumesFrom
121+
workingDirectory = var.workingDirectory == "" ? "null" : var.workingDirectory
122+
}
123+
)
86124

87-
container_definitions = replace(local.container_definition, "/\"(null)\"/", "$1")
88-
}
125+
container_definition = var.register_task_definition ? format("[%s]", local.template_file) : format("%s", data.template_file)
89126

90-
data "template_file" "container_definition" {
91-
template = file("${path.module}/templates/container-definition.json.tpl")
92-
93-
vars = {
94-
command = local.command == "[]" ? "null" : local.command
95-
cpu = var.cpu == 0 ? "null" : var.cpu
96-
disableNetworking = var.disableNetworking ? true : false
97-
dnsSearchDomains = local.dnsSearchDomains == "[]" ? "null" : local.dnsSearchDomains
98-
dnsServers = local.dnsServers == "[]" ? "null" : local.dnsServers
99-
dockerLabels = local.dockerLabels == "{}" ? "null" : local.dockerLabels
100-
dockerSecurityOptions = local.dockerSecurityOptions == "[]" ? "null" : local.dockerSecurityOptions
101-
entryPoint = local.entryPoint == "[]" ? "null" : local.entryPoint
102-
environment = local.environment == "[]" ? "null" : local.environment
103-
essential = var.essential ? true : false
104-
extraHosts = local.extraHosts == "[]" ? "null" : local.extraHosts
105-
healthCheck = local.healthCheck == "{}" ? "null" : local.healthCheck
106-
hostname = var.hostname == "" ? "null" : var.hostname
107-
image = var.image == "" ? "null" : var.image
108-
interactive = var.interactive ? true : false
109-
links = local.links == "[]" ? "null" : local.links
110-
linuxParameters = local.linuxParameters == "{}" ? "null" : local.linuxParameters
111-
logConfiguration = local.logConfiguration == "{}" ? "null" : local.logConfiguration
112-
memory = var.memory == 0 ? "null" : var.memory
113-
memoryReservation = var.memoryReservation == 0 ? "null" : var.memoryReservation
114-
mountPoints = local.mountPoints == "[]" ? "null" : local.mountPoints
115-
name = var.name == "" ? "null" : var.name
116-
portMappings = local.portMappings == "[]" ? "null" : local.portMappings
117-
privileged = var.privileged ? true : false
118-
pseudoTerminal = var.pseudoTerminal ? true : false
119-
readonlyRootFilesystem = var.readonlyRootFilesystem ? true : false
120-
repositoryCredentials = local.repositoryCredentials == "{}" ? "null" : local.repositoryCredentials
121-
resourceRequirements = local.resourceRequirements == "[]" ? "null" : local.resourceRequirements
122-
secrets = local.secrets == "[]" ? "null" : local.secrets
123-
systemControls = local.systemControls == "[]" ? "null" : local.systemControls
124-
ulimits = local.ulimits == "[]" ? "null" : local.ulimits
125-
user = var.user == "" ? "null" : var.user
126-
volumesFrom = local.volumesFrom == "[]" ? "null" : local.volumesFrom
127-
workingDirectory = var.workingDirectory == "" ? "null" : var.workingDirectory
128-
}
127+
container_definitions = replace(local.container_definition, "/\"(null)\"/", "$1")
129128
}
130129

131130
resource "aws_ecs_task_definition" "ecs_task_definition" {

0 commit comments

Comments
 (0)