Provision the DynamoDB Table

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
resource "aws_dynamodb_table" "dynamodb-terraform-state-lock" {
  name = "terraform-state-lock-dynamo"
  hash_key = "LockID"
  read_capacity = 20
  write_capacity = 20
 
  attribute {
    name = "LockID"
    type = "S"
  }
}

Configure the DynamoDB table in Terraform Backend

1
2
3
4
5
6
7
8
9
terraform {
  backend "s3" {
    encrypt = true
    bucket = "your-unique-bucket-name"
    dynamodb_table = "terraform-state-lock-dynamo"
    key    = "terraform.tfstate"
    region = "us-east-1"
  }
}