Skip to content

Instantly share code, notes, and snippets.

@fgcui1204
Created January 15, 2020 16:41
Show Gist options
  • Save fgcui1204/e490d95f1891c7018cbeda68d1e8f55c to your computer and use it in GitHub Desktop.
Save fgcui1204/e490d95f1891c7018cbeda68d1e8f55c to your computer and use it in GitHub Desktop.
terraform-remote-state-store
provider "aws" {
region = "ap-southeast-1"
version = "~> 2.43"
}
resource "aws_s3_bucket" "terraform_state_fgcui" {
bucket = "terraform-up-and-running-state-fgcui"
# Prevent accidental deletion of this S3 bucket
lifecycle {
prevent_destroy = true
}
# 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-up-and-running-locks"
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
}
terraform {
backend "s3" {
bucket = "terraform-up-and-running-state-fgcui"
key = "global/s3/terraform.tfstate"
region = "ap-southeast-1"
dynamodb_table = "terraform-up-and-running-locks"
encrypt = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment