Terraform/AWS - Error while acquiring state lock

26 views Asked by At

I am creating a simple Terraform state file in S3, following is the code that I am using

terraform {
  backend "s3" {
    bucket = "terraform-state-bucket"
    key    = "global/s3/terraform.state"
    region = "us-east-1"
    dynamodb_table = "dynamodb_state"
    encrypt        = true
  }

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }

  }
}

resource "aws_s3_bucket" "terraform_state" {
  bucket = "terraform-state-bucket"
  lifecycle {
    prevent_destroy = true
  }
}

resource "aws_dynamodb_table" "terraform_state_dynamodb" {
  name         = "dynamodb_state"
  billing_mode = "PAY_PER_REQUEST"
  hash_key     = "LockId"
  attribute {
    name = "LockId"
    type = "S"
  }
}

Following is the error that I am seeing, not able to figure out the issue. Any help is appreciated.

│ Error: Error acquiring the state lock
│ 
│ Error message: 2 errors occurred:
│       * ValidationException: One or more parameter values were invalid: Missing the key LockId in the item
│       status code: 400, request id: KR5NR5J5BBE1DITNG4SCTEL5UNVV4KQNSO5AEMVJF66Q9ASUAAJG
│       * ValidationException: The provided key element does not match the schema
│       status code: 400, request id: 8JJ9A2R8Q93OPSSCSC8GIRB3AJVV4KQNSO5AEMVJF66Q9ASUAAJG
0

There are 0 answers