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)
}