Skip to content

Feature request: allow manual remote state locking #17203

Closed

Description

@2rs2ts

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.

Activity

  1. jbardin commented on Jan 28, 2018

    @jbardin
    Member

    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.

  2. minamijoyo commented on Dec 20, 2019

    @minamijoyo
    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!

  3. ghost locked and limited conversation to collaborators on Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址