Skip to content

Commit

Permalink
Format, update editorconfig format
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomationD committed May 8, 2024
1 parent 0974c2c commit 861a1ac
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
Expand Down
24 changes: 12 additions & 12 deletions modules/ecs-service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
] : []


Expand Down
2 changes: 1 addition & 1 deletion modules/ecs-service/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ""
}
32 changes: 16 additions & 16 deletions modules/ecs-service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
}


Expand Down Expand Up @@ -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."
}
}
Expand Down Expand Up @@ -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" {
Expand All @@ -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" {}
Expand Down
4 changes: 2 additions & 2 deletions modules/ecs-task/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" = "",
Expand All @@ -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" = "",
Expand Down
62 changes: 33 additions & 29 deletions modules/ecs-task/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -150,11 +154,11 @@ locals {
]
},
{
"Action" = [
"kms:Decrypt"
],
"Effect" = "Allow",
"Resource" = "*"
"Action" = [
"kms:Decrypt"
],
"Effect" = "Allow",
"Resource" = "*"
}
])
}
Expand Down
2 changes: 1 addition & 1 deletion modules/ecs-task/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions modules/ecs-task/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
Expand Down Expand Up @@ -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 = {}
}


Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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" {}
Expand Down

0 comments on commit 861a1ac

Please sign in to comment.