ci: delete failed EKS node groups before retrying terraform destroy - #38721
Conversation
QA LLM Review (Post Merge)@bobbyiliev — an automated review of commit 1. HIGH --
|
|
Confirmed and fixed in #38731, thanks. Reproduced against the CI-pinned Terraform 1.13.5: with resources in state and #38731 reads the |
…38731) Follow-up to #38721, which does not work. `unblock_destroy` took the cluster name from `terraform output -raw eks_cluster_name`, but a destroy removes the root outputs before the resources they reference, so by the time a destroy has failed the state has no outputs left while the cluster is still in it. `terraform output -raw` then exits 0 and writes a 540-character "No outputs found" warning to stdout rather than stderr, so no `CalledProcessError` fires and the `if not cluster` guard sees a non-empty string. The banner was passed to `aws eks list-nodegroups --cluster-name`, which failed, and the swallowed error left the hook silently inert: the leak it targets still happened, with no log line to say so. Thanks @def- for catching it. `_eks_cluster_name` now reads the `aws_eks_cluster` resource out of `terraform state pull`, since resources survive a failed destroy, and requires the name to match `[A-Za-z0-9][A-Za-z0-9_-]*` so no future unexpected stdout can reach the AWS CLI. It also logs when no cluster is found, so an inert hook is distinguishable from one that ran with nothing to do. ### Test plan The reported behavior is confirmed against the CI-pinned Terraform 1.13.5: with a state carrying resources and `"outputs": {}`, `terraform output -raw eks_cluster_name` exits 0 with 540 bytes on stdout and nothing on stderr. The new parser was exercised against the real leaked state from Nightly 18272 and returns `aws-test-dev-eks` both as uploaded and with its outputs stripped, returns empty for a fully destroyed state, and rejects the warning banner as a name. End to end it still needs a destroy that fails with a node group attached, so the AWS nightlies remain the real check. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
An EKS node group whose creation fails keeps its cluster undeletable (
ResourceInUseException: Cluster has nodegroups attached), and Terraform does not retry the node group once the cluster delete fails, so all threeterraform destroyattempts hit the same wall and the run leaks its cluster, VPC, KMS key and log groups. Because each AWS test root uses a fixed name prefix and every run starts from empty state, that leak then fails every later nightly on "already exists" within minutes, which is how one bad apply in Nightly 18263 turned into an open-ended outage of both AWS Terraform nightlies.State.destroynow calls anunblock_destroyhook between attempts, which AWS overrides to delete any attached node groups and wait for them to go away before the next attempt.Test plan
The failure path needs a real EKS cluster with a
CREATE_FAILEDnode group, so it is exercised by a Nightly on this branch (the branch name matches the two AWS jobs'*terraform*filter). The healthy path is unchanged: the hook only runs after aterraform destroyattempt has already failed, and the base implementation is a no-op, so GCP and Azure keep their current behavior.🤖 Generated with Claude Code