When creating an EKS cluster using Terraform (terraform apply), if the user wants to stop the cluster creation and terminate the cluster that is being created, how should he proceed?
Terraform apply acquires a lock to protect the directories/files if uses to create the cluster. Is it possible to gracefully stop the terraform apply so that a “terraform destroy” can be issued for that cluster that is being created and succeed (without the need to wait for the cluster to actually be fully created)?
If Terraform CLI is interrupted (e.g. ctrl+c, SIGINT) during the apply phase then it will send a request to all of the providers to cancel their active requests and stop as soon as possible.
It’s ultimately up to each provider to decide how to implement that cancellation. In the ideal case the provider is able to stop immediately and return an error, but not all providers and not all upstream APIs can support that sort of cancellation.
Terraform Core will wait until all active requests to providers are complete (either successfully or errored) before exiting, but it cannot force providers to complete cancellation promptly, and so some providers may continue running certain requests even after cancellation.
If you send a second interruption to Terraform CLI after Terraform Core is already in the state where it’s trying to exit gracefully, it will instead exit ungracefully, which will leave the working directory and latest state snapshot however they are at that instant. In that case, you will typically need to take manual repair actions before you can continue.
If the resource type representing an EKS cluster in the AWS provider does not respond promptly to cancellation, that may be caused by a limitation of the AWS provider or by a limitation of the underlying EKS API. If that’s true then probably the only way to improve the situation would be to improve the AWS provider behavior in a later version of the provider; this is not something you can control from outside of the provider code.
Thanks for responding to my inquiry. The info you provided is definitely helpful.