ECS plan fails if cluster has been deleted outside Terraform #15917
Labels
bug
Addresses a defect in current functionality.
service/ecs
Issues and PRs that pertain to the ecs service.
Milestone
Community Note
Terraform CLI and Terraform AWS Provider Version
Affected Resource(s)
Terraform Configuration Files
Service.json is taken straight from the example in the docs https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition
Debug Output
I cannot provide the full debug output because of security restrictions with my employer but this is the relevant section:
Panic Output
Expected Behavior
I created an ECS cluster with an associated service then manually deleted the cluster and the service in the console (or as part of a regular clean up script). When I run a plan again, I expect it to produce a valid plan to re-create the cluster and the service.
Actual Behavior
I created an ECS cluster with an associated service then manually deleted the cluster and the service in the console. When I run a plan again, terraform outputs
Error: Error reading ECS service: ClusterNotFoundException: Cluster not found.
Steps to Reproduce
terraform apply
to create the cluster and serviceterraform plan
Important Factoids
When an ECS cluster and service are deleted, they are put in an inactive state and disappear from the UI but are not actually removed from the account. Described Here. As long as they exist in an inactive state there is no issue. What we've seen happen is the cluster being removed completely such that
aws ecs describe-clusters --clusters <cluster-arn>
produces an error instead of returning an inactive cluster. During the failed plan I see a sequence of events like:ecs/DescribeClusters
with the expected cluster ARN from state[WARN] ECS Cluster (arn:aws:ecs:us-east-1::cluster/my-cluster) not found, removing from state
ecs/DescribeServices
with the expected service and cluster ARN from stateSo it seems like terraform needs to interpret a ClusterNotFoundException as a sign of needing to re-create the service.
It's difficult to fully replicate the issue because it depends on the cluster being removed from the account. I'm not sure how long that takes. I've had two internal customers come to me with this issue within 2 weeks of an account clean up. I was able to re-create for my simple example by updating the state of the service to point to a cluster that never existed.
References
The text was updated successfully, but these errors were encountered: