Error waiting for ECS Cluster to become Available: unexpected state 'FAILED', wanted target 'ACTIVE')

Hi,

When trying to create a new cluster along side with a new capacity provider attached to it I see the below error that the ecs cluster is unavailble and on the console the cluster is created in failed state. I am able to create the ecs cluster without capcity provider attached to it, but when I try to create it with the capcity provider atttached to it fails with the below error. I am currently using Terraform version v0.12.31 with aws provider version: 3.74.2 where I am seeing this issue. Could you please help/guide on this issue we are seeing.

Error
Error: error waiting for ECS Cluster to become Available: unexpected state ‘FAILED’, wanted target ‘ACTIVE’. last error: %!s()

Code Snippet

`
resource “random_id” “cp_unique_id” {
count = local.enabled

keepers = {
auto_scaling_group_arn = var.ecs_asg_arn
}

byte_length = 8
}

resource “aws_ecs_capacity_provider” “capacity_provider” {
count = local.create_capacity_provider

name = “{var.name}-{local.environment}-capProvider-${random_id.cp_unique_id[count.index].hex}”

auto_scaling_group_provider {
auto_scaling_group_arn = var.ecs_asg_arn
managed_termination_protection = var.ecs_asg_termination_protection

managed_scaling {
instance_warmup_period = var.instance_warmup_period
status = var.managed_scaling_status
target_capacity = var.managed_target_capacity
maximum_scaling_step_size = var.managed_max_scaling_step_size
minimum_scaling_step_size = var.managed_min_scaling_step_size
}
}

tags = merge(local.std_tags, var.tags)

lifecycle {
create_before_destroy = true
}
}

resource “aws_ecs_cluster” “ecs_cluster” {
count = local.enabled
depends_on = [aws_ecs_capacity_provider.capacity_provider]

name = “{var.name}-{local.environment}-ecsCluster”

capacity_providers = [aws_ecs_capacity_provider.capacity_provider[count.index].name]

tags = merge(local.std_tags, var.tags)
}

name about
:bug: Bug Report Trying to create an ecs cluster with a capacity provider attached to it, which is failing to create the ecs cluster with name "self-services using the below attached terraform code.

Terraform CLI and Terraform AWS Provider Version

Terraform version = 0.12.31
AWS Provider version = 4.2

Affected Resource(s)

aws_ecs_cluster
aws_ecs_capacity_provider

Terraform Configuration Files

Below is the terraform code used shared through dropbox.

Debug Output

**Error:** **error waiting for ECS Cluster to become Available: unexpected state 'FAILED', wanted target 'ACTIVE'. last error: %!s(<nil>)**

on ../ec2-ecs-cluster/main.tf line 36, in resource "aws_ecs_cluster" "ecs_cluster":

36: resource "aws_ecs_cluster" "ecs_cluster" {

Expected Behavior

Expected to create Capacity Provider and an ECS Cluster with the capacity provider attached to it.

Actual Behavior

The Capacity provider is being created from the plan but the ECS Cluster creation is failing when trying to create it with capacity provider attached to it with above error in the debug output session.

Steps to Reproduce

  1. unzip ECS-CLusterWithCP.zip
  2. cd ECS-CLusterWithCP/aws-setup/
  3. vi main.tf Please add an existing autscaling group arn in main.tf line 9 for value “ecs_asg_arn”.
    4.vi provider.tf and add profile to be used in line 3 for value “profile”.
  4. terraform init
  5. terraform plan
    7.trerraform apply