- Newest
- Most votes
- Most comments
It turns out a capacity provider can be associated with an ECS cluster while its association is not explicitly shown anywhere. As I have mentioned in my question the capacity provider was created with Terraform. In order to make the association with a cluster it seems like you have to declare a aws_ecs_cluster_capacity_providers and specify which capacity providers are associated with a cluster. At first I did not declare the resource in my Terraform module because it seemed only useful when creating the cluster along with the module. Because the cluster was not created within the module and the work was done on an existing cluster and when declaring aws_ecs_cluster_capacity_providers seems like you have to specify not only the capacity providers you want to add but the existing ones. And then I found no other way to make the association so I declared aws_ecs_cluster_capacity_providers temporarily. I did not add FARGATE and FARGATE_SPOT because it seemed like it was supplied to the cluster by default and cannot be removed anyway. I think this is where my problem was.
One way to disassociate a capacity provider from a cluster is to use PutClusterCapacityProviders API and specify the capacity providers to associate and others that weren't mentioned in the API call would be disassociated. I tried this and wouldn't work until I added FARGATE and FARGATE_SPOT.
I attempted to add the capacity provider which was claimed to be associated with the cluster along with FARGATE and FARGATE_SPOT and the API call was processed and then the capacity provider was visible from the management console and from AWS CLI. Then I was able to delete it.
Make sure that a capacity provider is not included in any service's capacity provider strategy before deleting it. You can use the UpdateService API to remove a capacity provider from a service's capacity provider strategy. You can also use the forceNewDeployment option to move any tasks that use the Amazon EC2 instance capacity from the provider to the remaining capacity providers.
https://docs.aws.amazon.com/cli/latest/reference/ecs/delete-capacity-provider.html
Following the deletion of an Auto Scaling group, the related capacity provider will enter an INACTIVE state. While this state may remain in your account for a while, you should not depend on INACTIVE capacity providers because their behavior is subject to change.
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/delete-capacity-provider-console-v2.html
Capacity providers that are associated with a cluster cannot be directly deleted. To delete such a provider, you first need to remove it from the cluster. This can be done using the PutClusterCapacityProviders API or by deleting the cluster itself
https://docs.aws.amazon.com/cli/latest/reference/ecs/delete-capacity-provider.html
Relevant content
- Accepted Answerasked 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
As I have stated I have checked that my capacity provider is not included in any service's capacity provider strategy as guided in https://repost.aws/knowledge-center/ecs-capacity-provider-error.