'Terraform state file locked and stuck can't complete
while running terraform plan i did a CTRL C on a windows computer and now when i try to run terraform plan again i get
Error: Error loading state: 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.
I tried
terraform force-unlock id
but that gives me
Local state cannot be unlocked by another process
I am kind of stuck and cannot move forward
Much appreciated if someone can please assist.
Regards, KKR
Solution 1:[1]
Did you save the state file in s3 or local? If it is from remote, try to delete that state file first and retry. If it is local process, you will need to kill the process and delete the state file from your local folder .terraform/terraform.tfstate
Solution 2:[2]
i had to kill the terraform process and then resume
Solution 3:[3]
I faced this issue when trying to run a Terraform Init and Terraform Plan from two different instances of AzureCLI task (a similar AWS task in your case). Move all the terraform commands to a single instance of the task and that should fix the issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MattYao |
| Solution 2 | KKR |
| Solution 3 | Ajay Meda |
