title: Capacity provider instances not being added to cluster
body: <p>I'm new to AWS and I'm trying to provision an ECS cluster with a capacity provider via Terraform. My plan executes without errors currently, and I can see that the capacity provider creates my instances, but those instances are not being registered with the cluster, even though the provider can be seen in the cluster's edit page in the web console.</p>
  <p>Here is my config for the cluster:</p>
  <pre><code>resource &quot;aws_ecs_cluster&quot; &quot;cluster&quot; {
    name = &quot;main&quot;
  
    depends_on = [
      null_resource.iam_wait
    ]
  }
  
  data &quot;aws_ami&quot; &quot;amazon_linux_2&quot; {
    most_recent = true
    owners      = [&quot;amazon&quot;]
  
    filter {
      name   = &quot;name&quot;
      values = [&quot;amzn2-ami-ecs-hvm-*-x86_64-ebs&quot;]
    }
  }
  
  resource &quot;aws_launch_configuration&quot; &quot;cluster&quot; {
    name = &quot;cluster-${aws_ecs_cluster.cluster.name}&quot;
    image_id = data.aws_ami.amazon_linux_2.image_id
    instance_type = &quot;t2.small&quot;
  
    security_groups = [module.vpc.default_security_group_id]
    iam_instance_profile = aws_iam_instance_profile.cluster.name
  }
  
  resource &quot;aws_autoscaling_group&quot; &quot;cluster&quot; {
    name = aws_ecs_cluster.cluster.name
    launch_configuration = aws_launch_configuration.cluster.name
    vpc_zone_identifier = module.vpc.private_subnets
  
    min_size = 3
    max_size = 3
    desired_capacity = 3
  
    tag {
      key = &quot;ClusterName&quot;
      value = aws_ecs_cluster.cluster.name
      propagate_at_launch = true
    }
  
    tag {
      key = &quot;AmazonECSManaged&quot;
      value = &quot;&quot;
      propagate_at_launch = true
    }
  }
  
  resource &quot;aws_ecs_capacity_provider&quot; &quot;cluster&quot; {
    name = aws_ecs_cluster.cluster.name
  
    auto_scaling_group_provider {
      auto_scaling_group_arn = aws_autoscaling_group.cluster.arn
  
      managed_scaling {
        status = &quot;ENABLED&quot;
        maximum_scaling_step_size = 1
        minimum_scaling_step_size = 1
        target_capacity = 3
      }
    }
  }
  
  resource &quot;aws_ecs_cluster_capacity_providers&quot; &quot;cluster&quot; {
    cluster_name = aws_ecs_cluster.cluster.name
  
    capacity_providers = [aws_ecs_capacity_provider.cluster.name]
  
    default_capacity_provider_strategy {
      base = 1
      weight = 100
      capacity_provider = aws_ecs_capacity_provider.cluster.name
    }
  }
  </code></pre>
  <p>The instance profile role has this policy:</p>
  <pre><code>{
    &quot;Version&quot;: &quot;2012-10-17&quot;,
    &quot;Statement&quot;: [
      {
        &quot;Effect&quot;: &quot;Allow&quot;,
        &quot;Action&quot;: [
          &quot;ec2:DescribeTags&quot;,
          &quot;ecs:CreateCluster&quot;,
          &quot;ecs:DeregisterContainerInstance&quot;,
          &quot;ecs:DiscoverPollEndpoint&quot;,
          &quot;ecs:Poll&quot;,
          &quot;ecs:RegisterContainerInstance&quot;,
          &quot;ecs:StartTelemetrySession&quot;,
          &quot;ecs:Submit*&quot;,
          &quot;ecr:GetAuthorizationToken&quot;,
          &quot;ecr:GetDownloadUrlForLayer&quot;,
          &quot;ecr:BatchGetImage&quot;,
          &quot;ecr:BatchCheckLayerAvailability&quot;,
          &quot;logs:CreateLogStream&quot;,
          &quot;logs:PutLogEvents&quot;
        ],
        &quot;Resource&quot;: &quot;*&quot;
      }
    ]
  }
  </code></pre>
  <p>I've read that this can happen if the instances do not have the proper roles, but as far as I can tell I've set up my roles correctly. I'm not getting any visible permission errors that I can find.</p>
  <p>Another strange thing I've seen is that if another cluster named &quot;default&quot; exists, then the instances will register themselves to that cluster, even though the capacity provider is still attached to the other cluster.</p>