-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Terraform console creates a lock that does not go away before it's closed #23655
Comments
Could I check how this issue proceed? I have received similar issues from my customer when run tfstate.lock.info {"ID":"753dd145-4007-3fb5-00c9-58876ea44d8a","Operation":"OperationTypeInvalid","Info":"","Who":"WIN-5P0ODUDEVVF\Administrator@LGUPLUS-PC","Version":"0.14.2","Created":"2020-12-18T06:36:20.2570009Z","Path":"terraform.tfstate"} $ terraform plan Error: Error locking state: Error acquiring the state lock: Failed to read state file: The state file could not be read: read terraform.tfstate: The process cannot access the file because another process has locked a portion of the file. Terraform acquires a state lock to protect the state from being written And then $ terraform force-unlock 753dd145-4007-3fb5-00c9-58876ea44d8a |
Just got hit by this myself.... took a while to figure out 😅 |
Best would be to add an argument |
@tringuyen-yw better still to implement it as |
Any update on this, it's been an open issue for a long time. When you strike the issue the error says to run with -lock=false. but this does not work so this makes it a bug. |
This would be a welcome feature. Our terraform developers dont have write access to the gcp bucket where we keep our tfstate. They run |
Agree, this really needs to be fixed. Needs a -lock=false option |
Hi all. May I implement this improvement? I’m interested in terraform contribution and this issue is a good first one. |
Hi @kazuki-hanai, before you work on a pull request, please check out https://github.com/hashicorp/terraform/blob/main/.github/CONTRIBUTING.md#proposing-a-change - specifically:
This would be the first step to making this contribution, so if you do decide to move forward please start with the discussion of a potential solution. I raised this issue in a triage meeting in May 2022. That meeting did not have the benefit of the later use cases. Here is an overview of the feedback: Broadly speaking, the console feature is intended for configuration language experimentation, rather than to be built into production workflows (with all respect to anyone who is using console in such a workflow). We want console to be as safe to use as possible. Another core assumption is that the console will not be left open indefinitely, unreasonably holding open locks. One possible solution would be to acquire and release a lock on every statement execution. This solution would have a relatively high overhead, but is more feasible than a command-line option that would disable locks entirely. In general, the team is not adding new command line options. So a solution that avoided adding a new argument would be preferred. I hope this helps guide you in the right direction when proposing a solution! |
I don't know why it should keep a lock. Last time I checked, it couldn't modify anything (may have changed). |
Hi @crw, I don't get your argumentation. Following case:
Where I don't doubt that it is a good thing to hold a lock, I'm a bit lost here:
Now you argue to have "console as save to use as possible" and thus not want to implement -lock=false leaves the thing inconsistent. Thanks for the great work 👍 |
I'm also confused as to why the console would need to create a lock file if it can't actually change anything. From my understanding, it only reads the current state file from the defined backend and can not make changes to the current state. Correct me if I'm wrong here. This debugging tool is super useful, and should never be used in a production pipeline. But when we are debugging with this tool and our pipeline runs while a developer is using the tool for debugging reasons, the lock file is present in remote storage and the pipeline fails. This should not be the intended function of a debugging tool. |
Apologies for the late response. The team would be happy to consider a PR that adds a |
Have given this a quick crack. hopefully itll get through soon. |
Terraform Version
Expected Behavior
When i run "terraform console" I expect it to to only lock state remotely long enough to do data lookups. Once the prompt is displayed, I would expect the lock to be released.
Actual Behavior
When i run "terraform console" it creates a lock in the remote state that isn't released until I close the console.
Steps to Reproduce
terraform console
on a project with shared state on machine A, leave the console openterraform console
on a project with shared state on machine BThe text was updated successfully, but these errors were encountered: