Unable to unlock terraform lock file

I have got into a situation where I have a lock on the tfstate file. I am trying this from my local

I tried the force-unlock command but no luck. What is the way to unlock in such case?

While the interface for all state locks is the same, how they are implemented depends on the storage being used. In this case if you have a local state file, terraform cannot unlock it from outside the process holding the lock. The way to unlock that file would be to stop the terraform process which currently using the state file.

@jbardin Thank you for the response. We have S3 bucket implemented for the state file. I tried running the from the Jenkins server, still getting the same error.

there are no processes running when I checked using this command

ps aux | grep terraform

Here is the backend config

terraform {
  backend "s3" {
    bucket               = "project-api-terraform"
    key                  = "terraform.tfstate"
    workspace_key_prefix = "workspace"
    region               = "us-east-1"
    dynamodb_table       = "project-api-terraform"
    encrypt              = true
  }
}

Are you certain you are running the commands from the same environment? The error shows “local state cannot be unlocked by another process”, which means there is no backend config, or it is set to local.

The issue is resolved. I did a terraform init using root user in local then ran the force-unlock command and I was able to remove the lock. Thanks for your help.