From 861a1ac54d7dbf176700ed7f20be5d9a36651cb6 Mon Sep 17 00:00:00 2001 From: Dmitry Kireev Date: Wed, 8 May 2024 11:40:03 +0000 Subject: [PATCH] Format, update editorconfig format --- .editorconfig | 2 +- modules/ecs-service/main.tf | 24 ++++++------- modules/ecs-service/outputs.tf | 2 +- modules/ecs-service/variables.tf | 32 ++++++++--------- modules/ecs-task/iam.tf | 4 +-- modules/ecs-task/locals.tf | 62 +++++++++++++++++--------------- modules/ecs-task/main.tf | 2 +- modules/ecs-task/variables.tf | 30 ++++++++-------- 8 files changed, 81 insertions(+), 77 deletions(-) diff --git a/.editorconfig b/.editorconfig index 88cb251..d4f4302 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,7 +11,7 @@ end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true -max_line_length = 80 +max_line_length = 300 trim_trailing_whitespace = true [*.{tf,tfvars}] diff --git a/modules/ecs-service/main.tf b/modules/ecs-service/main.tf index 5e6768d..88e252f 100644 --- a/modules/ecs-service/main.tf +++ b/modules/ecs-service/main.tf @@ -19,7 +19,7 @@ module "task" { docker_container_links = var.docker_container_links - environment = var.environment + environment = var.environment # Non-secret Environment variables app_secrets = local.app_secrets global_secrets = local.global_secrets @@ -106,13 +106,13 @@ resource "aws_ecs_service" "this" { dynamic "load_balancer" { for_each = var.app_type == "web" || var.app_type == "tcp-app" ? [ - for port_mapping in var.port_mappings : { - container_name = port_mapping.container_name - target_group_arn = port_mapping.target_group_arn - container_port = port_mapping.container_port + for port_mapping in var.port_mappings : { + container_name = port_mapping.container_name + target_group_arn = port_mapping.target_group_arn + container_port = port_mapping.container_port - } - ]: [] + } + ] : [] content { target_group_arn = load_balancer.value.target_group_arn @@ -180,11 +180,11 @@ resource "aws_ecs_service" "this_deployed" { dynamic "load_balancer" { for_each = var.app_type == "web" || var.app_type == "tcp-app" ? [ - for p in var.port_mappings : { - container_name = p.container_name - container_port = p.container_port - target_group_arn = p.target_group_arn - } + for p in var.port_mappings : { + container_name = p.container_name + container_port = p.container_port + target_group_arn = p.target_group_arn + } ] : [] diff --git a/modules/ecs-service/outputs.tf b/modules/ecs-service/outputs.tf index 28b199c..2f3fd12 100644 --- a/modules/ecs-service/outputs.tf +++ b/modules/ecs-service/outputs.tf @@ -15,5 +15,5 @@ output "cloudwatch_log_group" { output "cloudwatch_event_rule_id" { description = "Cloudwatch event rule for ECS Scheduled Task" - value = (var.app_type == "worker" && length(var.cloudwatch_schedule_expressions)>0) ? aws_cloudwatch_event_rule.this[0].id : "" + value = (var.app_type == "worker" && length(var.cloudwatch_schedule_expressions)>0) ? aws_cloudwatch_event_rule.this[0].id : "" } diff --git a/modules/ecs-service/variables.tf b/modules/ecs-service/variables.tf index a6d5f31..a6f874a 100644 --- a/modules/ecs-service/variables.tf +++ b/modules/ecs-service/variables.tf @@ -161,7 +161,7 @@ variable "sidecar_container_definitions" { variable "additional_container_definition_parameters" { type = any description = "Additional parameters passed straight to the container definition, eg. tmpfs config" - default = {} + default = {} } @@ -189,7 +189,7 @@ variable "cpu" { default = 256 validation { - condition = can(regex("256|512|1024|2048|4096", var.cpu)) + condition = can(regex("256|512|1024|2048|4096", var.cpu)) error_message = "The cpu value must be a valid CPU value, https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html." } } @@ -362,9 +362,9 @@ variable "autoscale_scheduled_down" { } variable "autoscale_scheduled_timezone" { - type = string + type = string description = "Time Zone for the scheduled event" - default = "UTC" + default = "UTC" } variable "ecs_exec_enabled" { @@ -380,40 +380,40 @@ variable "firelens_ecs_log_enabled" { } variable "tmpfs_enabled" { - type = bool + type = bool description = "TMPFS support for non-Fargate deployments" - default = false + default = false } variable "tmpfs_size" { - type = number + type = number description = "Size of the tmpfs in MB" - default = 1024 + default = 1024 } variable "tmpfs_container_path" { - type = string + type = string description = "Path where tmpfs shm would be mounted" - default = "/tmp/" + default = "/tmp/" } variable "tmpfs_mount_options" { - type = list(string) + type = list(string) description = "Options for the mount of the ram disk. noatime by default to speed up access" - default = ["noatime"] + default = ["noatime"] } variable "shared_memory_size" { - type = number + type = number description = "Size of the /dev/shm shared memory in MB" - default = 0 + default = 0 } variable "docker_labels" { - type = map(any) + type = map(any) description = "Labels to be added to the docker. Used for auto-configuration, for instance of JMX discovery" - default = null + default = null } variable "operating_system_family" {} diff --git a/modules/ecs-task/iam.tf b/modules/ecs-task/iam.tf index 1ce8795..9e65b7f 100644 --- a/modules/ecs-task/iam.tf +++ b/modules/ecs-task/iam.tf @@ -8,7 +8,7 @@ resource "aws_iam_role" "ecs_execution" { name = "${var.env}-${var.name}-ecs-execution-role" assume_role_policy = jsonencode({ - "Version" = "2012-10-17", + "Version" = "2012-10-17", "Statement" = [ { "Sid" = "", @@ -32,7 +32,7 @@ resource "aws_iam_role" "ecs_task_role" { name = "${var.env}-${var.name}-ecs-task-role" assume_role_policy = jsonencode({ - "Version" = "2012-10-17", + "Version" = "2012-10-17", "Statement" = [ { "Sid" = "", diff --git a/modules/ecs-task/locals.tf b/modules/ecs-task/locals.tf index 9644ba8..d852c19 100644 --- a/modules/ecs-task/locals.tf +++ b/modules/ecs-task/locals.tf @@ -3,7 +3,7 @@ locals { docker_container_command = (var.docker_container_command == [] ? [] : var.docker_container_command) docker_container_entrypoint = (var.docker_container_entrypoint == [] ? [] : var.docker_container_entrypoint) - ssm_secret_path = var.ssm_secret_path != null ? var.ssm_secret_path : "/${var.env}/${var.name}" + ssm_secret_path = var.ssm_secret_path != null ? var.ssm_secret_path : "/${var.env}/${var.name}" ssm_global_secret_path = var.ssm_global_secret_path != null ? var.ssm_global_secret_path : "/${var.env}/global" # ECS Task Container definition file is filled with content here @@ -15,7 +15,7 @@ locals { image = "${var.docker_image_name}:${var.docker_image_tag}" resourceRequirements = var.resource_requirements - dockerLabels: var.docker_labels + dockerLabels : var.docker_labels cpu = var.ecs_launch_type == "FARGATE" ? var.cpu : null @@ -34,39 +34,43 @@ locals { linuxParameters = var.operating_system_family == "LINUX" ? { sharedMemorySize = (var.shared_memory_size > 0 && var.ecs_launch_type != "FARGATE") ? var.shared_memory_size : null - tmpfs = (var.tmpfs_enabled && var.ecs_launch_type != "FARGATE") ? [ + tmpfs = (var.tmpfs_enabled && var.ecs_launch_type != "FARGATE") ? [ { ContainerPath = var.tmpfs_container_path - MountOptions = var.tmpfs_mount_options - Size = var.tmpfs_size - }] : null, + MountOptions = var.tmpfs_mount_options + Size = var.tmpfs_size + } + ] : null, initProcessEnabled = var.ecs_exec_enabled ? true : null } : null mountPoints = [ - # This way we ensure that we only mount main app volumes to the main app container. - for volume in var.volumes : lookup(volume, "mount_point", {}) if(contains(keys(volume), "mount_point")) + # This way we ensure that we only mount main app volumes to the main app container. + for volume in var.volumes : lookup(volume, "mount_point", {}) if(contains(keys(volume), "mount_point")) ] environment = [for k, v in local.environment : { name = k, value = v }] - secrets = concat([for param_name in var.app_secrets : - { - name = param_name - valueFrom = "arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter${local.ssm_secret_path}/${param_name}" - } - ], [for param_name in var.global_secrets : - { - name = replace(param_name, "/", "") != param_name ? element(split("/", param_name), 1) : param_name - valueFrom = "arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter${local.ssm_global_secret_path}/${param_name}" - } + secrets = concat([ + for param_name in var.app_secrets : + { + name = param_name + valueFrom = "arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter${local.ssm_secret_path}/${param_name}" + } + ], [ + for param_name in var.global_secrets : + { + name = replace(param_name, "/", "") != param_name ? element(split("/", param_name), 1) : param_name + valueFrom = "arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter${local.ssm_global_secret_path}/${param_name}" + } ]) - portMappings = [for p in var.port_mappings : - { - containerPort = p.container_port - hostPort = p.host_port - } + portMappings = [ + for p in var.port_mappings : + { + containerPort = p.container_port + hostPort = p.host_port + } ] links = var.docker_container_links @@ -106,7 +110,7 @@ locals { iam_ecs_execution_role_policy = { - "Version" = "2012-10-17", + "Version" = "2012-10-17", "Statement" = concat(var.iam_role_policy_statement, [ { "Effect" = "Allow", @@ -150,11 +154,11 @@ locals { ] }, { - "Action" = [ - "kms:Decrypt" - ], - "Effect" = "Allow", - "Resource" = "*" + "Action" = [ + "kms:Decrypt" + ], + "Effect" = "Allow", + "Resource" = "*" } ]) } diff --git a/modules/ecs-task/main.tf b/modules/ecs-task/main.tf index 8ab707b..9baa714 100644 --- a/modules/ecs-task/main.tf +++ b/modules/ecs-task/main.tf @@ -47,7 +47,7 @@ resource "aws_ecs_task_definition" "this" { requires_compatibilities = [ var.ecs_launch_type ] - container_definitions = jsonencode(local.container_definitions) + container_definitions = jsonencode(local.container_definitions) runtime_platform { operating_system_family = var.operating_system_family diff --git a/modules/ecs-task/variables.tf b/modules/ecs-task/variables.tf index 647427c..012a118 100644 --- a/modules/ecs-task/variables.tf +++ b/modules/ecs-task/variables.tf @@ -21,7 +21,7 @@ variable "cpu" { default = 256 validation { - condition = can(regex("256|512|1024|2048|4096", var.cpu)) + condition = can(regex("256|512|1024|2048|4096", var.cpu)) error_message = "The cpu value must be a valid CPU value, https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html." } } @@ -135,7 +135,7 @@ variable "sidecar_container_definitions" { variable "additional_container_definition_parameters" { type = any description = "Additional parameters passed straight to the container definition, eg. tmpfs config" - default = {} + default = {} } @@ -176,7 +176,7 @@ variable "ecs_network_mode" { variable "ecs_network_configuration" { type = map(any) description = "ECS Network Configuration" - default = {} + default = {} } variable "ecs_task_family_name" { @@ -227,40 +227,40 @@ variable "firelens_ecs_log_enabled" { } variable "tmpfs_enabled" { - type = bool + type = bool description = "TMPFS support for non-Fargate deployments" - default = false + default = false } variable "tmpfs_size" { - type = number + type = number description = "Size of the tmpfs in MB" - default = 1024 + default = 1024 } variable "tmpfs_container_path" { - type = string + type = string description = "Path where tmpfs tmpfs would be mounted" - default = "/tmp/" + default = "/tmp/" } variable "tmpfs_mount_options" { - type = list(string) + type = list(string) description = "Options for the mount of the ram disk. noatime by default to speed up access" - default = ["noatime"] + default = ["noatime"] } variable "shared_memory_size" { - type = number + type = number description = "Size of the /dev/shm shared memory in MB" - default = 0 + default = 0 } variable "docker_labels" { - type = map(any) + type = map(any) description = "Labels to be added to the docker. Used for auto-configuration, for instance of JMX discovery" - default = null + default = null } variable "operating_system_family" {}