Skip to content
Lucas de Macedo edited this page Apr 23, 2024 · 3 revisions

Welcome to the terraform-aws-ecs-app-worker wiki!

Example use case:

module "ecs_app_worker" {
  for_each = { for worker in try(local.workspace.ecs.workers, {}) : worker.name => worker }
  source   = "git::https://github.com/DNXLabs/terraform-aws-ecs-app-worker.git?ref=2.5.0"

  cluster_name     = each.value.cluster_name
  vpc_id           = data.aws_vpc.selected[0].id
  desired_count    = each.value.desired_count
  cpu              = each.value.cpu
  memory           = each.value.memory
  image            = "${shared_service_account}.dkr.ecr.ap-southeast-2.amazonaws.com/${each.value.image_name}:latest"

  name                                    = each.value.name
  alarm_sns_topics                        = try([local.workspace.notifications_sns_topic_arn], [])
  alarm_prefix                            = "${local.workspace.org_name}-${local.workspace.account_name}"
  cloudwatch_logs_export                  = each.value.cloudwatch_logs_export
  log_subscription_filter_enabled         = false
  log_subscription_filter_role_arn        = ""
  log_subscription_filter_destination_arn = ""

  launch_type     = try(each.value.launch_type, "EC2")
  fargate_spot    = try(each.value.fargate_spot, false)
  network_mode    = try(each.value.launch_type, "EC2") == "FARGATE" ? "awsvpc" : null
  security_groups = try(each.value.launch_type, "EC2") == "FARGATE" ? [module.ecs_cluster[each.value.cluster_name].ecs_nodes_secgrp_id] : null
  subnets         = try(each.value.launch_type, "EC2") == "FARGATE" ? data.aws_subnets.private.ids : null
}

Example Workspace:

ecs:
  clusters:
    - name: staging
      alb: true
      alb_http_listener: true
      alb_sg_allow_test_listener: true
      alg_sg_allow_egress_https_world: true
      certificate_arn: "arn:aws:acm:ap-southeast-2:<ACCOUNT>:certificate/<CERTIFICATE_ID>"
  workers:
    - name: "application-tasks-worker"
      cluster_name: "staging"
      cloudwatch_logs_export: true
      image_name: application-tasks-worker
      launch_type: "FARGATE"
      fargate_spot: true
      desired_count: 1
      memory: 2048
      cpu: 1024
Clone this wiki locally