Ecs ec2 server based - error target type instance, which is incompatible with the awsvpc

resource “aws_ecs_task_definition” “tasks1role” {

family = “mytasks”

network_mode = “awsvpc”

placement_constraints {

type       = "memberOf"

expression = "attribute:ecs.availability-zone in [ us_east-1a , us-east-1b , us-east-1c]"

}

task_role_arn = aws_iam_role.rolelist.arn

execution_role_arn = aws_iam_role.rolelist.arn

container_definitions = jsonencode([

{

  name      = "site2"

  image     = "117337261428.dkr.ecr.us-east-1.amazonaws.com/myrepo:latest"

  memory    = 256

  essential = true

  portMappings = [

    {

      containerPort = 80

      hostPort      = 80

    }

  ]

},

])

requires_compatibilities = [“EC2”]

volume {

name      = "tasks-storage"

host_path = "/ecs/tasks-storage"

}

}

resource “aws_ecs_service” “service1role” {

name = “east1service”

network_configuration {

security_groups  = [aws_security_group.secure2grp.id]

subnets          = [aws_subnet.sbnts2[0].id, aws_subnet.sbnts2[1].id, aws_subnet.sbnts2[2].id]

assign_public_ip = false

}

launch_type = “EC2”

load_balancer {

target_group_arn = aws_lb_target_group.albgrp.arn

container_name   = "site2"

container_port   = 80

}

cluster = aws_ecs_cluster.east1cluster.id

task_definition = aws_ecs_task_definition.tasks1role.id

desired_count = 2

ordered_placement_strategy {

type  = "spread"

field = "cpu"

}

}

resource “aws_ecs_cluster” “east1cluster” {

name = “est1clster”

setting {

name  = "containerInsights"

value = "enabled"

}

capacity_providers = [aws_ecs_capacity_provider.caprvdr.name]

}

resource “aws_ecs_capacity_provider” “caprvdr” {

name = “mycapcity”

auto_scaling_group_provider {

auto_scaling_group_arn         = aws_autoscaling_group.grp11.arn

managed_termination_protection = "DISABLED"

}

}

resource “aws_launch_template” “temp21” {

image_id = var.tools[“amieast1”]

instance_type = var.tools[“types”]

key_name = var.tools[“keys2”]

vpc_security_group_ids = [aws_security_group.secure2grp.id]

block_device_mappings {

device_name = "/dev/sdk"

ebs {

  volume_size = 8

  volume_type = "gp2"

}

}

user_data = filebase64("./order2.sh")

iam_instance_profile {

arn = aws_iam_instance_profile.profileecr.arn

}

}

resource “aws_autoscaling_group” “grp11” {

name = “scale2grp”

min_size = 2

max_size = 8

desired_capacity = 6

default_cooldown = 300

vpc_zone_identifier = [aws_subnet.sbnts2[0].id, aws_subnet.sbnts2[1].id, aws_subnet.sbnts2[2].id]

launch_template {

id      = aws_launch_template.temp21.id

version = "$Latest"

}

health_check_type = “ELB”

health_check_grace_period = 300

tag {

key                 = "AmazonECSManaged"

value               = ""

propagate_at_launch = true

}

}

resource “aws_autoscaling_attachment” “attach” {

alb_target_group_arn = aws_lb_target_group.albgrp.arn

autoscaling_group_name = aws_autoscaling_group.grp11.id

}

resource “aws_lb” “myalb” {

name = “eastlb”

load_balancer_type = “application”

idle_timeout = 120

ip_address_type = “ipv4”

subnets = [aws_subnet.sbnts1[0].id, aws_subnet.sbnts1[1].id, aws_subnet.sbnts1[2].id]

security_groups = [aws_security_group.secure4grp.id]

}

resource “aws_lb_listener” “auth” {

load_balancer_arn = aws_lb.myalb.arn

port = 80

protocol = “HTTP”

default_action {

target_group_arn = aws_lb_target_group.albgrp.arn

type             = "forward"

}

}

resource “aws_lb_listener_rule” “list” {

listener_arn = aws_lb_listener.auth.arn

action {

target_group_arn = aws_lb_target_group.albgrp.arn

type             = "forward"

}

condition {

http_request_method {

  values = ["GET", "HEAD"]

}

}

}

resource “aws_lb_target_group” “albgrp” {

load_balancing_algorithm_type = “round_robin”

port = 80

protocol = “HTTP”

vpc_id = aws_vpc.vpcs.id

health_check {

interval            = 6

timeout             = 2

healthy_threshold   = 2

unhealthy_threshold = 2

port                = 80

protocol            = "HTTP"

path                = "/"

}

target_type = “instance”

}

could somebody explain to me whats mean by this error and what cause of it and whats solution for it

You need to change target_type in albgrp to ip address.