|
| 1 | +data "aws_region" "current" {} |
| 2 | + |
| 3 | +locals { |
| 4 | + secret_names = concat(var.secret_names, [ |
| 5 | + "PASSWORD" |
| 6 | + ]) |
| 7 | + |
| 8 | + environment = merge(var.environment, |
| 9 | + { |
| 10 | + ECS_FARGATE = var.ecs_launch_type == "FARGATE" ? "true" : "false" |
| 11 | + } |
| 12 | + ) |
| 13 | + |
| 14 | + container_definition = { |
| 15 | + name = var.name |
| 16 | + image = "${var.docker_image_name}:${var.docker_image_tag}", |
| 17 | + memoryReservation = var.docker_memory_reservation, |
| 18 | + essential = true, |
| 19 | + resourceRequirements = var.resource_requirements |
| 20 | + |
| 21 | + environment = [for k, v in local.environment : { name = k, value = v }] |
| 22 | + secrets = module.ssm.secrets |
| 23 | + |
| 24 | + portMappings = [{ |
| 25 | + containerPort = var.docker_container_port, |
| 26 | + // In case of bridge an host use a dynamic port (0) |
| 27 | + hostPort = var.ecs_network_mode == "awsvpc" ? var.docker_container_port : 0 |
| 28 | + }] |
| 29 | + |
| 30 | + // This is used to make sure the app container has started before starting proxy (for nginx config to be copied to a volume and for port reachibility) |
| 31 | + dependsOn = [{ |
| 32 | + containerName = var.app_name, |
| 33 | + condition = "START" |
| 34 | + }], |
| 35 | + |
| 36 | + // This is used to map nginx config template from a volume (which can be created by the original app container) |
| 37 | + mountPoints = var.enabled ? [ |
| 38 | + { |
| 39 | + sourceVolume = "nginx-templates", |
| 40 | + containerPath = "/etc/nginx/templates/" |
| 41 | + } |
| 42 | + ] : [] |
| 43 | + |
| 44 | + logConfiguration = var.cloudwatch_log_group == "" ? { |
| 45 | + logDriver = "json-file" |
| 46 | + options = {} |
| 47 | + } : { |
| 48 | + logDriver = "awslogs", |
| 49 | + options = { |
| 50 | + awslogs-group = var.cloudwatch_log_group |
| 51 | + awslogs-region = data.aws_region.current.name |
| 52 | + awslogs-stream-prefix = var.name |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +module "ssm" { |
| 59 | + source = "hazelops/ssm-secrets/aws" |
| 60 | + version = "~> 1.0" |
| 61 | + env = var.env |
| 62 | + app_name = var.app_name |
| 63 | + names = var.enabled ? local.secret_names : [] |
| 64 | +} |
0 commit comments