KKR
KKR

Reputation: 67

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

Upvotes: 2

Views: 22114

Answers (3)

Ajay Meda
Ajay Meda

Reputation: 378

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.

Upvotes: 0

MattYao
MattYao

Reputation: 2555

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

Upvotes: 1

KKR
KKR

Reputation: 67

i had to kill the terraform process and then resume

Upvotes: 0

Related Questions