Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: allow manual remote state locking #17203

Closed
2rs2ts opened this issue Jan 25, 2018 · 3 comments
Closed

Feature request: allow manual remote state locking #17203

2rs2ts opened this issue Jan 25, 2018 · 3 comments

Comments

@2rs2ts
Copy link
Contributor

2rs2ts commented Jan 25, 2018

Currently, backend providers can implement locking during operations that can write state. This happens automatically. And there is a force-unlock command for when things go wrong.

A command for manually locking without running an operation that can write state would be useful. If your backend supports it, it would write the lock but do nothing to the state. Perhaps a command to remove that manual lock would be useful as well.

@jbardin
Copy link
Member

jbardin commented Jan 28, 2018

Hi @2rs2ts,

When planning the implementation for state locks, we made the decision to not handle this particular use case. If desired, options like this can be provided by external automation and workflow systems. The force-unlock command is more of a failsafe, and only works for certain types of locks in some backends.

In practice, many backends may not even support maintaining a lock on a state without the command running. For example, in consul the lock is tied to the calling process being responsive, so the lock is released as soon as the terraform process exits.

@minamijoyo
Copy link
Contributor

Hi, those who need terraform lock command.

I know Terraform doesn't provide terraform lock command by design. Nevertheless, I found it's useful to lock state manually when refactoring Terraform configurations. Let me share my use case and context.

In team development, Terraform configurations are generally managed by VCS such as git, and states are shared via a remote state storage which outside of version control. Most Terraform refactorings require not only configuration changes but also state manipulations such as state mv / rm / import. It is not desirable to change state before merging configuration changes. My colleague may be working for another task. I don't want team members to change the state during refactoring to avoid unexpected conflicts.

So I wrote an unofficial tool for locking Terraform state manually.
https://github.com/minamijoyo/tflock

Currently, it is tested only with Terraform 0.12 + AWS S3 (locked with DynamoDB).
The tflock uses a state lock function as same as Terraform uses under the hood. So other backend types may or may not work. Please be careful.

Thanks!

@ghost
Copy link

ghost commented Dec 21, 2019

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.

@ghost ghost locked and limited conversation to collaborators Dec 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants