Skip to content

Commit f49ece5

Browse files
committed
refactor: Initial pass at variable type definitions for container definition module
1 parent dd7de06 commit f49ece5

File tree

7 files changed

+271
-216
lines changed

7 files changed

+271
-216
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
- '--args=--only=terraform_documented_variables'
1818
- '--args=--only=terraform_typed_variables'
1919
- '--args=--only=terraform_module_pinned_source'
20-
- '--args=--only=terraform_naming_convention'
20+
# - '--args=--only=terraform_naming_convention' # Disabled due to container definition variables requiring camelCase
2121
- '--args=--only=terraform_required_version'
2222
- '--args=--only=terraform_required_providers'
2323
- '--args=--only=terraform_standard_module_structure'

examples/fargate/main.tf

+4-6
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,14 @@ module "ecs_service" {
162162
subnet_ids = module.vpc.private_subnets
163163
security_group_ingress_rules = {
164164
alb_ingress_3000 = {
165-
description = "Service port"
166-
from_port = local.container_port
167-
ip_protocol = "tcp"
168-
source_security_group_id = module.alb.security_group_id
165+
description = "Service port"
166+
from_port = local.container_port
167+
ip_protocol = "tcp"
168+
referenced_security_group_id = module.alb.security_group_id
169169
}
170170
}
171171
security_group_egress_rules = {
172172
egress_all = {
173-
to_port = 0
174173
ip_protocol = "-1"
175174
cidr_ipv4 = "0.0.0.0/0"
176175
}
@@ -226,7 +225,6 @@ module "ecs_task_definition" {
226225

227226
security_group_egress_rules = {
228227
egress_all = {
229-
to_port = 0
230228
ip_protocol = "-1"
231229
cidr_ipv4 = "0.0.0.0/0"
232230
}

modules/container-definition/README.md

+32-31
Large diffs are not rendered by default.

modules/container-definition/main.tf

+34-39
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ locals {
55

66
log_group_name = try(coalesce(var.cloudwatch_log_group_name, "/aws/ecs/${var.service}/${var.name}"), "")
77

8-
log_configuration = merge(
8+
logConfiguration = merge(
99
{ for k, v in {
1010
logDriver = "awslogs",
1111
options = {
@@ -14,58 +14,52 @@ locals {
1414
awslogs-stream-prefix = "ecs"
1515
},
1616
} : k => v if var.enable_cloudwatch_logging },
17-
var.log_configuration
17+
var.logConfiguration
1818
)
1919

20-
linux_parameters = var.enable_execute_command ? merge({ "initProcessEnabled" : true }, var.linux_parameters) : merge({ "initProcessEnabled" : false }, var.linux_parameters)
21-
22-
health_check = length(var.health_check) > 0 ? merge({
23-
interval = 30,
24-
retries = 3,
25-
timeout = 5
26-
}, var.health_check) : null
20+
linuxParameters = var.enable_execute_command ? merge(var.linuxParameters, { "initProcessEnabled" : true }) : var.linuxParameters
2721

2822
definition = {
29-
command = length(var.command) > 0 ? var.command : null
23+
command = var.command
3024
cpu = var.cpu
31-
dependsOn = length(var.dependencies) > 0 ? var.dependencies : null # depends_on is a reserved word
32-
disableNetworking = local.is_not_windows ? var.disable_networking : null
33-
dnsSearchDomains = local.is_not_windows && length(var.dns_search_domains) > 0 ? var.dns_search_domains : null
34-
dnsServers = local.is_not_windows && length(var.dns_servers) > 0 ? var.dns_servers : null
35-
dockerLabels = length(var.docker_labels) > 0 ? var.docker_labels : null
36-
dockerSecurityOptions = length(var.docker_security_options) > 0 ? var.docker_security_options : null
37-
entrypoint = length(var.entrypoint) > 0 ? var.entrypoint : null
25+
dependsOn = var.dependsOn
26+
disableNetworking = local.is_not_windows ? var.disableNetworking : null
27+
dnsSearchDomains = local.is_not_windows ? var.dnsSearchDomains : null
28+
dnsServers = local.is_not_windows ? var.dnsServers : null
29+
dockerLabels = var.dockerLabels
30+
dockerSecurityOptions = var.dockerSecurityOptions
31+
entrypoint = var.entrypoint
3832
environment = var.environment
39-
environmentFiles = length(var.environment_files) > 0 ? var.environment_files : null
33+
environmentFiles = var.environmentFiles
4034
essential = var.essential
41-
extraHosts = local.is_not_windows && length(var.extra_hosts) > 0 ? var.extra_hosts : null
42-
firelensConfiguration = length(var.firelens_configuration) > 0 ? var.firelens_configuration : null
43-
healthCheck = local.health_check
35+
extraHosts = local.is_not_windows ? var.extraHosts : null
36+
firelensConfiguration = var.firelensConfiguration
37+
healthCheck = var.healthCheck
4438
hostname = var.hostname
4539
image = var.image
4640
interactive = var.interactive
47-
links = local.is_not_windows && length(var.links) > 0 ? var.links : null
48-
linuxParameters = local.is_not_windows && length(local.linux_parameters) > 0 ? local.linux_parameters : null
49-
logConfiguration = length(local.log_configuration) > 0 ? local.log_configuration : null
41+
links = local.is_not_windows ? var.links : null
42+
linuxParameters = local.is_not_windows ? local.linuxParameters : null
43+
logConfiguration = length(local.logConfiguration) > 0 ? local.logConfiguration : null
5044
memory = var.memory
51-
memoryReservation = var.memory_reservation
52-
mountPoints = var.mount_points
45+
memoryReservation = var.memoryReservation
46+
mountPoints = var.mountPoints
5347
name = var.name
54-
portMappings = var.port_mappings
48+
portMappings = var.portMappings
5549
privileged = local.is_not_windows ? var.privileged : null
56-
pseudoTerminal = var.pseudo_terminal
57-
restartPolicy = var.restart_policy
58-
readonlyRootFilesystem = local.is_not_windows ? var.readonly_root_filesystem : null
59-
repositoryCredentials = length(var.repository_credentials) > 0 ? var.repository_credentials : null
60-
resourceRequirements = length(var.resource_requirements) > 0 ? var.resource_requirements : null
61-
secrets = length(var.secrets) > 0 ? var.secrets : null
62-
startTimeout = var.start_timeout
63-
stopTimeout = var.stop_timeout
64-
systemControls = length(var.system_controls) > 0 ? var.system_controls : []
65-
ulimits = local.is_not_windows && length(var.ulimits) > 0 ? var.ulimits : null
50+
pseudoTerminal = var.pseudoTerminal
51+
restartPolicy = var.restartPolicy
52+
readonlyRootFilesystem = local.is_not_windows ? var.readonlyRootFilesystem : null
53+
repositoryCredentials = var.repositoryCredentials
54+
resourceRequirements = var.resourceRequirements
55+
secrets = var.secrets
56+
startTimeout = var.startTimeout
57+
stopTimeout = var.stopTimeout
58+
systemControls = var.systemControls
59+
ulimits = local.is_not_windows ? var.ulimits : null
6660
user = local.is_not_windows ? var.user : null
67-
volumesFrom = var.volumes_from
68-
workingDirectory = var.working_directory
61+
volumesFrom = var.volumesFrom
62+
workingDirectory = var.workingDirectory
6963
}
7064

7165
# Strip out all null values, ECS API will provide defaults in place of null/empty values
@@ -77,6 +71,7 @@ resource "aws_cloudwatch_log_group" "this" {
7771

7872
name = var.cloudwatch_log_group_use_name_prefix ? null : local.log_group_name
7973
name_prefix = var.cloudwatch_log_group_use_name_prefix ? "${local.log_group_name}-" : null
74+
log_group_class = var.cloudwatch_log_group_class
8075
retention_in_days = var.cloudwatch_log_group_retention_in_days
8176
kms_key_id = var.cloudwatch_log_group_kms_key_id
8277

0 commit comments

Comments
 (0)