Help and docs
Sign in

demo/acme-infra code browser

read-replica 4747b0a
Terraform · 35 lines · 995 B
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
resource "aws_ecs_cluster" "main" {
  name = "acme-prod"
}

resource "aws_ecs_task_definition" "api" {
  family                   = "acme-pay"
  requires_compatibilities = ["FARGATE"]
  network_mode             = "awsvpc"
  cpu                      = 512
  memory                   = 1024
  container_definitions = jsonencode([{
    name         = "acme-pay"
    image        = var.api_image
    portMappings = [{ containerPort = 8080 }]
    environment = [
      { name = "DATABASE_URL", value = "postgres://acme@${aws_db_instance.ledger.endpoint}/ledger" },
    ]
  }])
}

resource "aws_ecs_service" "api" {
  name            = "acme-pay"
  cluster         = aws_ecs_cluster.main.id
  task_definition = aws_ecs_task_definition.api.arn
  desired_count   = 3
  launch_type     = "FARGATE"
  network_configuration {
    subnets = aws_subnet.private[*].id
  }
  load_balancer {
    target_group_arn = aws_lb_target_group.api.arn
    container_name   = "acme-pay"
    container_port   = 8080
  }
}