Timeout setting for terraform binary


I have been using terraform binary to automate some VM deployment. While doing terraform apply, the plan gets executed and gets failed in sometime. But actually the plan is in process still. Terraform just gets failed after waiting until its default timeout.

Is there any way so that I can set timeout for terraform while doing terraform apply?

Hi @dasaratharajkumar.m,

Terraform itself has no “timeout” mechanism itself. However, you could arrange for your automation to send Terraform the SIGINT signal (or whatever is equivalent on your chosen OS; whatever Ctrl+C would typically do is the goal) after a timeout elapses, which will cause Terraform to send cancellation requests to all of the providers which have requests currently active, and then exit once the providers acknowledge the cancellation.

If you’re running Terraform on a Unix-based system, such as Linux, then you might have the timeout command available, which you can use to get the effect I described above:

# Send terraform SIGINT if it doesn't exit before
# two minutes have passed.
timeout --signal=INT --foreground 2m terraform apply tfplan

It’s often not safe to immediately cancel a provider action in progress, because underlying service APIs don’t themselves offer an explicit cancellation feature and the provider needs to observe the completion of the request in order to properly update the Terraform state. In the worst case then, provider operations already running will typically run to completion and return a result but Terraform Core won’t start any new actions after it receives the interrupt signal.

For cases where a provider is able to forward a cancellation request safely to the remote API, an operation in progress might be able to terminate sooner than it naturally would. That behavior depends on how the particular resource type was implemented in the provider, so I can’t make any promises about whether it’ll be supported for the specific resource types you are using.