Hello everyone! I hope you are enjoying the journey so far 😄 This short note is about the deprecation of the dynamodb_table parameter for S3 remote backend as a means of enabling state locking. We briefly discussed that in the previous lectures, so I thought it would be helpful to mention that there is an easier approach from Terraform version 1.10.x onwards! Now, it's not necessary to create a DynamoDB table to use state locking; instead, you can just set the new parameter use_lockfile to true, and the state locking will be handled natively within S3. You can find more information about the new functionality in this Terraform documentation page.

The change is as simple as migrating the s3 backend block from


backend "s3" {
  bucket         = "terraform-state-bucket"
  key            = "terraform.tfstate"
  region         = "eu-west-1"
  dynamodb_table = "my-dynamodb-table"
}

to

backend "s3" {
   bucket       = "terraform-state-bucket"
   key          = "terraform.tfstate"
   region       = "eu-west-1"
   use_lockfile = true
}

And then running the command terraform init -reconfigure to update the backend configuration (in case the project has already been initialized; otherwise you can run just terraform init). Once this is implemented, and you run the terraform apply commands in the CLI, you should see a new file created next to your state file:

And that should be it! Now there is no need to create and manage a separate DynamoDB table for having state locking 😄

📌 רקע: מה זה בכלל State Locking?