author avatar

soniya.rayabagi

Wed Feb 07 2024

Storing Terraform State in S3 with Encryption and DynamoDB Locking , instead of Storing locally : To improve security , you can configure Terraform to store its state file in an AWS S3 bucket with encryption and use DynamoDB for state locking. This setup prevents local state file risks, enables team access, and avoids state conflicts.

syntax : 

 terraform {
      backend "<BACKEND_NAME>" {
        [CONFIG...]
      }
}
example :

terraform {
  backend "s3" {
    bucket         = "my-terraform-state"
    key            = "state/production/terraform.tfstate"
    region         = "us-east-1"
    encrypt        = true
    dynamodb_table = "my-terraform-lock"
  }
}