diff --git a/_variables.tf b/_variables.tf index c58cc72..526a98f 100644 --- a/_variables.tf +++ b/_variables.tf @@ -54,6 +54,20 @@ variable "port" { description = "Port for target group to listen" } +variable "ports" { + default = [ + { + port = 80 + protocol = "tcp" + } + ] + description = "Port for target group to listen" + type = list(object({ + port = number + protocol = string + })) +} + variable "container_port" { default = "8080" description = "Port your container listens (used in the placeholder task definition)" @@ -129,7 +143,7 @@ variable "placement_constraints" { } variable "launch_type" { - default = "EC2" + default = "FARGATE" description = "The launch type on which to run your service. The valid values are EC2 and FARGATE. Defaults to EC2." } @@ -202,3 +216,50 @@ variable "security_group_nlb_inbound_cidrs" { default = ["0.0.0.0/0"] description = "NLB inbound allowed CIDRs for the security group." } + +variable "create_iam_codedeployrole" { + type = bool + default = true + description = "Create Codedeploy IAM Role for ECS or not." +} + +variable "codedeploy_role_arn" { + default = null + description = "Existing IAM CodeDeploy role ARN created by ECS cluster module" +} + +variable "efs_mapping" { + type = map(string) + description = "A map of efs volume ids and paths to mount into the default task definition" + default = {} +} + +variable "ulimits" { + type = list(object({ + name = string + hardLimit = number + softLimit = number + })) + description = "Container ulimit settings. This is a list of maps, where each map should contain \"name\", \"hardLimit\" and \"softLimit\"" + default = null +} + +variable "deployment_controller" { + default = "CODE_DEPLOY" + description = "Type of deployment controller. Valid values: CODE_DEPLOY, ECS, EXTERNAL." +} + +variable "codedeploy_wait_time_for_cutover" { + default = 0 + description = "Time in minutes to route the traffic to the new application deployment" +} + +variable "codedeploy_wait_time_for_termination" { + default = 0 + description = "Time in minutes to terminate the new deployment" +} + +variable "codedeploy_deployment_config_name" { + default = "CodeDeployDefault.ECSAllAtOnce" + description = "Specifies the deployment configuration for CodeDeploy" +} diff --git a/ecs-service.tf b/ecs-service.tf index c2f5009..9b906c3 100644 --- a/ecs-service.tf +++ b/ecs-service.tf @@ -7,10 +7,13 @@ resource "aws_ecs_service" "default" { health_check_grace_period_seconds = var.service_health_check_grace_period_seconds enable_execute_command = true - load_balancer { - target_group_arn = aws_lb_target_group.ecs_default_tcp.arn - container_name = var.name - container_port = var.container_port + dynamic "load_balancer" { + for_each = { for port in var.ports : port.port => port } + content { + target_group_arn = aws_lb_target_group.ecs_default_tcp[load_balancer.value.port].arn + container_name = var.name + container_port = load_balancer.value.port + } } dynamic "placement_constraints" { @@ -65,11 +68,12 @@ resource "aws_security_group" "ecs_service" { resource "aws_security_group_rule" "ecs_service_from_nlb" { - count = var.nlb ? 1 : 0 + # for_each = var.nlb == true ? { for port in var.ports : port.port => port } : [] + for_each = { for port in(var.nlb == true ? var.ports : []) : port.port => port } type = "ingress" - from_port = var.port - to_port = var.port - protocol = "tcp" + from_port = each.value.port + to_port = each.value.port + protocol = each.value.protocol security_group_id = aws_security_group.ecs_service.id source_security_group_id = aws_security_group.nlb[0].id }