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

add command for force-unlock #223

Merged

Conversation

alec-rabold
Copy link
Contributor

@alec-rabold alec-rabold commented Sep 28, 2021

Adds command for terraform force-unlock -force LOCK_ID [DIR]. Assumes the -force option as it's practically required in this context.

Regarding forceUnlockDirArgMaxVersion, the command docs appear to indicate that the [DIR] positional argument is still valid but it was effectively removed around v0.15.0 in this commit. Just wanted to clarify where that was coming from since it was failing v0.15.x+ test cases.

(Related to #222)

@radeksimko radeksimko added the enhancement New feature or request label Sep 30, 2021
@radeksimko
Copy link
Member

FWIW We have an open PR #100 which discusses the [DIR] positional argument, but have not yet decided whether/how to proceed with that PR.

Aside from that - do you mind sharing some details about your use case here?

My understanding is that when state remains locked and Terraform returns that error, it is for that exact reason that "something unexpected happened" and essentially manual intervention is recommended. i.e. I would not expect anyone to build any sort of automation script that automatically unlocks the the state.

@alec-rabold
Copy link
Contributor Author

Thanks for the context on chdir/[DIR], I think it makes sense to let that PR you mentioned guide the discussion there 👍

As for use cases, I agree that automatically unlocking the state comes with its fair share of risk and uncertainty.

Currently we're running Terraform in a Kubernetes ecosystem to support self-service manifests (sort of similar to aws-controllers-k8s). Every so often we're hit with edge-cases that lock a resource's state like OOM kills or other non-graceful terminations. Since the TF project files aren't meant to be accessed locally, we manually signal that a resource should force-unlock by using an annotation on the k8s object (we're running a home-grown force-unlock implementation).

All that being said though, I do think there's valid use-cases where a higher-order construct can decide whether or not to force-unlock automatically (e.g. leader-election in our case, possibly).

Copy link
Member

@kmoe kmoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this. The handling of [DIR] is consistent with other commands, and, as you note, the Terraform docs, although its use will produce an error in v0.15+. We could add a tf.compatible for it here, or we could wait for it to be caught in #121. I don't think it matters too much.

Await re-review by @radeksimko before merge.

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'm happy with this as well 👍🏻 Thanks for sharing the context.

@radeksimko radeksimko merged commit 07c60a0 into hashicorp:main Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants