diff --git a/README.md b/README.md index abd49f1..5713495 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ In addition you have the option to create or not : | Name | Version | |------|---------| | aws | n/a | +| random | n/a | ## Inputs @@ -66,6 +67,8 @@ In addition you have the option to create or not : | autoscaling\_scale\_in\_cooldown | Cooldown in seconds to wait between scale in events | `number` | `300` | no | | autoscaling\_scale\_out\_cooldown | Cooldown in seconds to wait between scale out events | `number` | `300` | no | | autoscaling\_target\_cpu | Target average CPU percentage to track for autoscaling | `number` | `50` | no | +| cloudwatch\_logs\_export | Whether to mark the log group to export to an S3 bucket (needs terraform-aws-log-exporter to be deployed in the account/region) | `bool` | `false` | no | +| cloudwatch\_logs\_retention | Specifies the number of days you want to retain log events in the specified log group. Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653. | `number` | `120` | no | | cluster\_name | n/a | `string` | `"Name of existing ECS Cluster to deploy this app to"` | no | | container\_port | Port your container listens (used in the placeholder task definition) | `string` | `"8080"` | no | | cpu | Hard limit for CPU for the container | `string` | `"0"` | no | @@ -78,6 +81,7 @@ In addition you have the option to create or not : | memory | Hard memory of the container | `string` | `"512"` | no | | name | Name of your ECS service | `any` | n/a | yes | | network\_mode | The Docker networking mode to use for the containers in the task. The valid values are none, bridge, awsvpc, and host. (REQUIRED IF 'LAUCH\_TYPE' IS FARGATE) | `any` | `null` | no | +| nlb | Flag to create the NLB | `bool` | `false` | no | | nlb\_arn | Networking LoadBalance ARN - Required if nlb=false or nlb\_internal=false | `string` | `""` | no | | nlb\_internal | Creates an Internal NLB for this service | `bool` | `false` | no | | ordered\_placement\_strategy | Service level strategy rules that are taken into consideration during task placement. List from top to bottom in order of precedence. The maximum number of ordered\_placement\_strategy blocks is 5. |
list(object({
field = string
expression = string
}))
| `[]` | no | diff --git a/_variables.tf b/_variables.tf index 10dbcb1..c06563a 100644 --- a/_variables.tf +++ b/_variables.tf @@ -108,7 +108,6 @@ variable "service_health_check_grace_period_seconds" { description = "Time until your container starts serving requests" } - variable "ordered_placement_strategy" { # This variable may not be used with Fargate! description = "Service level strategy rules that are taken into consideration during task placement. List from top to bottom in order of precedence. The maximum number of ordered_placement_strategy blocks is 5." diff --git a/nlb-target-group.tf b/nlb-target-group.tf index 20c062c..e5c43ea 100644 --- a/nlb-target-group.tf +++ b/nlb-target-group.tf @@ -1,5 +1,5 @@ resource "aws_lb_listener" "ecs_tcp" { - load_balancer_arn = var.nlb ? aws_lb.default[0].arn : var.nlb_arn + load_balancer_arn = var.nlb ? try(aws_lb.default[0].arn, "") : var.nlb_arn port = var.port protocol = "TCP" @@ -9,8 +9,14 @@ resource "aws_lb_listener" "ecs_tcp" { } } +resource "random_string" "tg_nlb_prefix" { + length = 4 + upper = false + special = false +} + resource "aws_lb_target_group" "ecs_default_tcp" { - name = "ecs-${var.cluster_name}-${var.name}-tcp" + name = format("%s-%s-tcp", substr("${var.cluster_name}-${var.name}", 0, 23), random_string.tg_nlb_prefix.result) port = var.port protocol = "TCP" vpc_id = var.vpc_id diff --git a/nlb.tf b/nlb.tf index bb9969f..92fdc5f 100644 --- a/nlb.tf +++ b/nlb.tf @@ -1,6 +1,12 @@ +resource "random_string" "nlb_prefix" { + length = 4 + upper = false + special = false +} + resource "aws_lb" "default" { count = var.nlb ? 1 : 0 - name = var.nlb_internal ? "ecs-${var.cluster_name}-${var.name}-internal" : "ecs-${var.cluster_name}-${var.name}" + name = var.nlb_internal ? format("%s-%s-int", substr("${var.cluster_name}-${var.name}", 0, 23), random_string.nlb_prefix.result) : format("%s-%s", substr("${var.cluster_name}-${var.name}", 0, 27), random_string.nlb_prefix.result) internal = var.nlb_internal load_balancer_type = "network" subnets = var.subnets diff --git a/route53-record.tf b/route53-record.tf index 67bb67f..7591569 100644 --- a/route53-record.tf +++ b/route53-record.tf @@ -10,5 +10,5 @@ resource "aws_route53_record" "hostname" { name = var.hostname type = "CNAME" ttl = "300" - records = var.nlb_internal ? [aws_lb.default[0].dns_name] : [data.aws_lb.nlb_selected[0].dns_name] + records = var.nlb_internal ? [aws_lb.default[0].dns_name] : [try(data.aws_lb.nlb_selected[0].dns_name, "")] }