|
| 1 | +variable "cluster_name" { |
| 2 | + description = "Name of the ECS cluster" |
| 3 | +} |
| 4 | + |
| 5 | +variable "service_name" { |
| 6 | + description = "Name of the ECS service" |
| 7 | +} |
| 8 | + |
| 9 | +variable "target_group_name" { |
| 10 | + description = "Name of the ALB target group. Defaults to the `cluster_name` if not set" |
| 11 | + default = "" |
| 12 | +} |
| 13 | + |
| 14 | +variable "environment" { |
| 15 | + description = "Enviropnment vars to pass to the container. Note: they will be visible in the task definition, so please don't pass any secrets here." |
| 16 | + type = map |
| 17 | + default = {} |
| 18 | + |
| 19 | +} |
| 20 | + |
| 21 | +variable "image" { |
| 22 | + description = "The image to use" |
| 23 | +} |
| 24 | + |
| 25 | +variable "cpu" { |
| 26 | + description = "Amount of CPU to use" |
| 27 | + default = 0 |
| 28 | +} |
| 29 | + |
| 30 | +variable "essential" { |
| 31 | + description = "Exit the task if contaner exits" |
| 32 | + default = true |
| 33 | +} |
| 34 | + |
| 35 | +variable "memory" { |
| 36 | + description = "Amount of maximum memory the container can use" |
| 37 | + default = 512 |
| 38 | +} |
| 39 | + |
| 40 | +variable "memory_reservation" { |
| 41 | + description = "Amount of reserved memory for the container" |
| 42 | + default = 256 |
| 43 | +} |
| 44 | + |
| 45 | +variable "container_port" { |
| 46 | + default = 0 |
| 47 | +} |
| 48 | + |
| 49 | +variable "task_role_arn" { |
| 50 | + type = string |
| 51 | + default = "" |
| 52 | +} |
| 53 | + |
| 54 | +variable "port_mappings" { |
| 55 | + type = list |
| 56 | + default = [] |
| 57 | +} |
| 58 | + |
| 59 | +variable "log_configuration" { |
| 60 | + type = object({ |
| 61 | + logDriver = string |
| 62 | + options = map(any) |
| 63 | + }) |
| 64 | + default = { logDriver = "", options = {} } |
| 65 | +} |
| 66 | + |
| 67 | +variable "deployment_minimum_healthy_percent" { |
| 68 | + description = "Minimum number of healty contianers during deployments" |
| 69 | + default = 50 |
| 70 | +} |
| 71 | + |
| 72 | +variable "deployment_maximum_percent" { |
| 73 | + description = "Maximum number of healty contianers during deployments" |
| 74 | + default = 200 |
| 75 | +} |
| 76 | + |
| 77 | +variable "desired_count" { |
| 78 | + default = 1 |
| 79 | +} |
| 80 | + |
| 81 | +locals { |
| 82 | + balanced = var.container_port > 0 |
| 83 | + target_group_name = coalesce(var.target_group_name, var.cluster_name) |
| 84 | + |
| 85 | + default_log_configuration = { |
| 86 | + "logDriver" = "awslogs" |
| 87 | + "options" = { |
| 88 | + "awslogs-group" = aws_cloudwatch_log_group.main[0].name |
| 89 | + "awslogs-region" = data.aws_region.current.name |
| 90 | + "awslogs-stream-prefix" = var.service_name |
| 91 | + } |
| 92 | + } |
| 93 | + log_awslogs = var.log_configuration["logDriver"] == "" |
| 94 | + log_configuration = local.log_awslogs ? local.default_log_configuration : var.log_configuration |
| 95 | + |
| 96 | + defaultPortMappings = [ |
| 97 | + { |
| 98 | + containerPort = var.container_port |
| 99 | + } |
| 100 | + ] |
| 101 | +} |
| 102 | + |
0 commit comments