Aws_lb_target_group target_type if ECS

if my aws_lb_target_group_attachment it is an ECS, which target type should be used at resource “aws_lb_target_group” ?.

thanks a lot

i have done
I have 2 modules, ALB, and fargate
##############

resource “aws_ecs_service” “main” {

#count = “${var.nometaskdefenitionsem_mont ? 1 : 0}”

#task_definition = “${aws_ecs_task_definition.ldap[count.index].arn}”

name = var.nometaskdefenition

cluster = aws_ecs_cluster.ldap.id

task_definition = “${aws_ecs_task_definition.ldap.arn}”

desired_count = 1

deployment_minimum_healthy_percent = 50

deployment_maximum_percent = 200

launch_type = “FARGATE”

scheduling_strategy = “REPLICA”

network_configuration {

security_groups = ["${var.SG_1}"]

subnets         = [var.subnet_id]

}

task definition needs to match task name · Issue #1276 · aws/amazon-ecs-agent · GitHub

#target_group_arn = “${aws_lb_target_group.ALB_TG.id}” aqui

load_balancer {

target_group_arn = var.aws_alb_target_group_arn

container_name   = var.container_definitions_name

container_port   = var.container_port

}

depends_on = [

aws_lb_listener.http  

]

/*

lifecycle {

ignore_changes = [task_definition, desired_count]

}*/

platform_version = “1.4.0”

}

############################################

resource “aws_lb_target_group_attachment” “apitest” {

target_group_arn = aws_lb_target_group.ALB_TG.arn

target_id = var.final_ecs_servico_id

port = 443

}

#########################################

resource “aws_lb_target_group” “ALB_TG” {

name_prefix = var.nomedoALB

port = 80

protocol = “HTTP”

vpc_id = var.final_vpc_id

deregistration_delay = 10

target_type = “ip”

health_check {

healthy_threshold   = 2

unhealthy_threshold = 2

interval            = 10

}

lifecycle {

create_before_destroy = true

}

}
################################################

FROM terraform apply output


module.fargate.aws_ecs_service.main will be created

  • resource “aws_ecs_service” “main” {
    • cluster = “arn:aws:ecs:eu-west-3:920768381054:cluster/80”

    • deployment_maximum_percent = 200

    • deployment_minimum_healthy_percent = 50

    • desired_count = 1

    • enable_ecs_managed_tags = false

    • iam_role = (known after apply)

    • id = (known after apply)

    • launch_type = “FARGATE”

    • name = “ldap_cross”

    • platform_version = “1.4.0”

    • scheduling_strategy = “REPLICA”

    • task_definition = “arn:aws:ecs:eu-west-3:920768381054:task-definition/fs-e22e0353:1”

    • wait_for_steady_state = false

    • load_balancer {

      • container_name = “ldap”
      • container_port = 3890
      • target_group_arn = “arn:aws:elasticloadbalancing:eu-west-3:920768381054:targetgroup/ALB20210407183718789400000001/fc5d2f40d89b42f6”
        }
    • network_configuration {

      • assign_public_ip = false
      • security_groups = [
        • “sg-00c3435cb421153a2”,
          ]
      • subnets = [
        • “subnet-0a1f126f5b582f378”,
          ]
          }
          }

module.fargate.aws_lb_listener.http will be created

  • resource “aws_lb_listener” “http” {
    • arn = (known after apply)

    • id = (known after apply)

    • load_balancer_arn = “arn:aws:elasticloadbalancing:eu-west-3:920768381054:loadbalancer/app/ALB/0a6bf1cd2e1249ab”

    • port = 80

    • protocol = “HTTP”

    • ssl_policy = (known after apply)

    • default_action {

      • order = (known after apply)
      • target_group_arn = “arn:aws:elasticloadbalancing:eu-west-3:920768381054:targetgroup/ALB20210407183718789400000001/fc5d2f40d89b42f6”
      • type = “forward”
        }
        }

module.fargate.local_file.criar_service_definition_json will be created

  • resource “local_file” “criar_service_definition_json” {
    • content = jsonencode(
      [
      + {
      + cpu = “2”
      + essential = true
      + image = “920768381054.dkr.ecr.eu-west-2.amazonaws.com/opendj-ldap:1.0.2
      + memory = “512”
      + mountPoints = [
      + {
      + containerPath = “/efs”
      + readOnly = false
      + sourceVolume = “efs_temp”
      },
      ]
      + name = “jenkins-agent”
      },
      ]
      )
    • directory_permission = “0777”
    • file_permission = “0777”
    • filename = “service.json”
    • id = (k2021/04/07 19:41:17 [DEBUG] command: asking for input: “Do you want to perform these actions?”
      nown after apply)
      }

module.fargate_net_core.aws_ecs_service.main will be created

  • resource “aws_ecs_service” “main” {
    • cluster = “arn:aws:ecs:eu-west-3:920768381054:cluster/80”

    • deployment_maximum_percent = 200

    • deployment_minimum_healthy_percent = 50

    • desired_count = 1

    • enable_ecs_managed_tags = false

    • iam_role = (known after apply)

    • id = (known after apply)

    • launch_type = “FARGATE”

    • name = “sigom-net-core”

    • platform_version = “1.4.0”

    • scheduling_strategy = “REPLICA”

    • task_definition = (known after apply)

    • wait_for_steady_state = false

    • load_balancer {

      • container_name = “net_core”
      • container_port = 3890
      • target_group_arn = “arn:aws:elasticloadbalancing:eu-west-3:920768381054:targetgroup/ALB20210407183718938300000001/1601b8d9268d2082”
        }
    • network_configuration {

      • assign_public_ip = false
      • security_groups = [
        • “sg-00c3435cb421153a2”,
          ]
      • subnets = [
        • “subnet-0a1f126f5b582f378”,
          ]
          }
          }

module.fargate_net_core.aws_ecs_task_definition.ldap will be created

  • resource “aws_ecs_task_definition” “ldap” {
    • arn = (known after apply)
    • container_definitions = jsonencode(
      [
      + {
      + cpu = 2
      + essential = true
      + image = “920768381054.dkr.ecr.eu-west-2.amazonaws.com/sigom-net-core:3.0.4
      + memory = 512
      + name = “net_core”
      + portMappings = [
      + {
      + containerPort = 3890
      + hostPort = 3890
      + protocol = “tcp”
      },
      ]
      },
      ]
      )
    • cpu = “256”
    • execution_role_arn = “arn:aws:iam::920768381054:role/ecs-task-definition-role”
    • family = “fs-e22e0353”
    • id = (known after apply)
    • memory = “512”
    • network_mode = “awsvpc”
    • requires_compatibilities = [
      • “FARGATE”,
        ]
    • revision = (known after apply)
    • task_role_arn = “arn:aws:iam::920768381054:role/ecs-task-definition-role”
      }

module.fargate_net_core.local_file.criar_service_definition_json will be created

  • resource “local_file” “criar_service_definition_json” {
    • content = jsonencode(
      [
      + {
      + cpu = “2”
      + essential = true
      + image = “920768381054.dkr.ecr.eu-west-2.amazonaws.com/sigom-net-core:3.0.4
      + memory = “512”
      + mountPoints = [
      + {
      + containerPath = “/efs”
      + readOnly = false
      + sourceVolume = “efs_temp”
      },
      ]
      + name = “jenkins-agent”
      },
      ]
      )
    • directory_permission = “0777”
    • file_permission = “0777”
    • filename = “service.json”
    • id = (known after apply)
      }

error message:

Error:2021-04-09T15:16:27.296+0100 [WARN] plugin.stdio: received EOF, stopping recv loop: err=“rpc error: code = Unavailable desc = transport is closing”
Error registering targets with target group: ValidationError: The IP address ‘arn:aws:ecs:eu-west-2:920768381054:service/80/ldap_cross’ is not a valid IPv4 address
status code: 400, request id: ba54f89f-7099-4ce5-8901-29e99f533531

Error: Error registering targets with target group: ValidationError: The IP address ‘arn:aws:ecs:eu-west-2:920768381054:service/80/ldap_cross’ is not a valid IPv4 address
status code: 400, request id: 6bab9d51-078f-4efa-94c5-52a51800ad50