terraform
terraform copied to clipboard
State lock info / unlock for automation purpose
Current Terraform Version
Terraform v0.15.3
on linux_amd64
Use-cases
Sometimes state locking happens on a CI/CD pipeline when there is abrupt cancellation or unexpected command error because of networking issue (or someone still using terraform manually outside CI/CD) If this happens, the next run on the same pipeline will fail because the state is still locked. State unlock will have to be done manually. It would be great if there is a command to list locks on a certain state, or forcefully unlock all all available locks on a certain state without stating lock ID. All this to ensure that every run on the pipeline will have no state locked issue without automatic unlocking feature available.
Attempted Solutions
No solution available as there is no command to list locks available. Locks only visible when command plan
or apply
is executed and to unlock, a lock ID must be known.
Proposal
Maybe command like :
terraform state lock list
to list locks existing on a state, json output will be great for easy parsing.
terraform state lock --unlock <lock-id>
to unlock a certain lock.
terraform state lock --unlock --all
to force unlock all existing lock without stating lock ID
Or maybe implement a lock expiry time that can be configured globally or per state
References
- #28194 state lock and unlock
still on the roadmap ?
This is a needed feature
I also want this feature added.
this feature is required.