# InvalidParameterException: the target group with targetGroupArn xxxxx does not have an associated load balancerAW

**URL:** <https://discuss.hashicorp.com/t/invalidparameterexception-the-target-group-with-targetgrouparn-xxxxx-does-not-have-an-associated-load-balanceraw/34025>\
**Category:** AWS\
**Created:** [January 10, 2022, 3:31am UTC](https://discuss.hashicorp.com/t/invalidparameterexception-the-target-group-with-targetgrouparn-xxxxx-does-not-have-an-associated-load-balanceraw/34025 "2022-01-10T03:31:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cakraocha](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/cakraocha/32/24982_2.png) [@cakraocha](https://discuss.hashicorp.com/u/cakraocha)\
**Post date:** [January 10, 2022, 3:31am UTC](https://discuss.hashicorp.com/t/invalidparameterexception-the-target-group-with-targetgrouparn-xxxxx-does-not-have-an-associated-load-balanceraw/34025/1 "2022-01-10T03:31:59Z")

</div>

Hey Guys,

The context is that I am trying to deploy a Fargate service with the load balancer setup, but I keep getting this error although I already followed the discussion at [[AWS] Creating of ALB, Target Group and Service in one script causes errors · Issue #12634 · hashicorp/terraform · GitHub](https://github.com/hashicorp/terraform/issues/12634)

Currently, a snippet of my code

```auto
resource "aws_lb" "main" {
  name = local.name
  internal = local.load_balancer_is_internal ? true : false
  load_balancer_type = "application"
  security_groups = [aws_security_group.lb.id]
  subnets = local.load_balancer_subnet_ids

  tags = merge(
    {
      Name = "${local.name}-lb-app_main"
    },
    local.tags
  )
}

resource "aws_lb_target_group" "main" {
  name = local.name
  port = local.app_port
  protocol = "HTTP"
  vpc_id = local.vpc_id
  target_type = "ip"

  health_check {
    protocol = "HTTP"
    matcher = "200-202"
    path = "/health"
  }

  depends_on = [
    aws_lb.main,
  ]
}

resource "aws_ecs_cluster" "app_main" {
  ...
}

resource "aws_ecs_task_definition" "app_main" {
  ...
}

resource "aws_ecs_service" "app_main" {
  name = local.name
  cluster = aws_ecs_cluster.app_main.id
  task_definition = aws_ecs_task_definition.main.arn
  desired_count = 2
  launch_type = "FARGATE"
  platform_version = "1.4.0"

  network_configuration {
    subnets = local.service_subnet_ids
    security_groups = [aws_security_group.ecs_service.id]
  }

  load_balancer {
    target_group_arn = aws_lb_target_group.main.arn
    container_name = "app-container"
    container_port = local.app_port
  }

  lifecycle {
    ignore_changes = [desired_count]
  }

  depends_on = [aws_lb_target_group.main]

  tags = merge(
    {
      Name = "${local.name}-ecs-service"
    },
    local.tags
  )
}

```

I tried creating fake dependencies, I tried to create depends on whenever possible, but the error still exists. I kinda getting frustrated. Is there anyone with this issue that already solve this problem? Maybe I missed other solution

Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![cakraocha](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/cakraocha/32/24982_2.png) [@cakraocha](https://discuss.hashicorp.com/u/cakraocha)\
**Post date:** [January 10, 2022, 5:06am UTC](https://discuss.hashicorp.com/t/invalidparameterexception-the-target-group-with-targetgrouparn-xxxxx-does-not-have-an-associated-load-balanceraw/34025/2 "2022-01-10T05:06:51Z")

</div>

Okay this is my bad. I forgot to provision a aws\_lb\_listener resource. Once I provisioned it, it works.
