Skip to content

Instantly share code, notes, and snippets.

@jeffbrl
Created December 22, 2020 16:49
Show Gist options
  • Save jeffbrl/4adbb8a82232a244997e3566e2291857 to your computer and use it in GitHub Desktop.
Save jeffbrl/4adbb8a82232a244997e3566e2291857 to your computer and use it in GitHub Desktop.
Terraform template to create S3 backend with DynamoDB lock
# Adapted from tips at https://blog.gruntwork.io/how-to-manage-terraform-state-28f5697e68fa
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "terraform_state" {
bucket = "uniqueBuckeName"
# Enable versioning so we can see the full revision history of our
# state files
versioning {
enabled = true
}
# Enable server-side encryption by default
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
}
resource "aws_dynamodb_table" "terraform_locks" {
name = "terraform-locking-table"
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment