Terraform: Ability to specify state locking timeout

Created on 21 Sep 2017  ·  4Comments  ·  Source: hashicorp/terraform

As a Terraform user I would like to specify a timeout for state locking. When running terraform plan against a backend with state locking enabled (e.g. aws provider with state locking via dynamodb) the current behaviour aborts with status code 1. 🙊

The Problem

When running deployments in a CI server it might happen that different pipelines execute the same Terraform component (e.g. to provision common infrastructure). It currently happens that a Terraform command fails due to a state lock acquired, however I want to wait for a specified amount of time (e.g. 1 minute), if a lock is currently present.

Possible Solution

Ideally, Terraform should accept a locking timeout, e.g.

dynamodb_table = "my-dynamodb-table"
locking_timeout = 60000 # 60 seconds

which then could be passed as -backend-config. This is not implemented in Terraform but I would like to have something like this in future.
I tried to build a workaround with bash, unfortunately Terraform exits always with status code 1 so it is not possible for me to distinguish between state locking or other failures.

Discuss!

Most helpful comment

Hi @bitbrain,

While we don't support the option in the backend configuration, Terraform plan and apply do have a -lock-timeout flag specifically for this use case.

All 4 comments

Hi @bitbrain,

While we don't support the option in the backend configuration, Terraform plan and apply do have a -lock-timeout flag specifically for this use case.

@jbardin how could I possibly miss that? I was reading through that doc page like 20 times today. Whoops... 😇

BTW terraform destroy also supports -lock-timeout=0s

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings