'Terraform Error: Error locking state: Error acquiring the state lock: 2 errors occurred:

I tried terraform versions v0.12.26 and v0.13.3. Both failed.

terraform plan

Acquiring state lock. This may take a few moments...

Error: Error locking state: Error acquiring the state lock: 2 errors occurred: * ResourceNotFoundException: Requested resource not found * ResourceNotFoundException: Requested resource not found

Terraform acquires a state lock to protect the state from being written by multiple users at the same time. Please resolve the issue above and try again. For most commands, you can disable locking with the "-lock=false" flag, but this is not recommended.

Related source code:

terraform {
  backend "s3" {
    encrypt        = false
    bucket         = "dev-terraform-state"
    key            = "dev/Oregon/eks/terraform.tfstate"
    region         = "us-west-2"
    dynamodb_table = "dev-lock-table"
  }
  required_version = ">= 0.12.0"
}


Solution 1:[1]

The error is ResourceNotFoundException, which suggests that your dev-lock-table does not exist.

Terraform does not create it. Instead it must exist before you will use it. From docs:

dynamodb_table field to an existing DynamoDB table name.

Solution 2:[2]

I ran terraform force-unlock <LOCK_ID> (docs) to delete the lock.

Lots of discussion here

Solution 3:[3]

Make sure the table created and region specified in below code are same

terraform { backend "s3" { bucket = "" key = "" region = "us-east-1" dynamodb_table =

Solution 4:[4]

Check if you're using the same AWS account and correct region. DynamoDB Table must be in the same region as CLI/SDK configuration

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
Solution 2 Chao jin
Solution 3 Sandeep_Jaina
Solution 4 Rajmohan