Skip to content

Instantly share code, notes, and snippets.

@Staggerlee011
Last active December 4, 2020 21:12
Show Gist options
  • Save Staggerlee011/b08b80dad659cd549030e5855a798673 to your computer and use it in GitHub Desktop.
Save Staggerlee011/b08b80dad659cd549030e5855a798673 to your computer and use it in GitHub Desktop.
Terraform template to create a secure s3 bucket, dnamodb for state file
provider "aws" {
region = "eu-west-2"
profile = "xxx"
}
variable "env" {
description = "Name of AWS environment"
type = string
default = "xxx"
}
resource "aws_s3_bucket" "terraform_state" {
bucket = "${var.env}-statefile"
# Enable versioning
versioning {
enabled = true
}
#Enable Server Side Encryption by default
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
}
# Block ALL public access to statefile bucket
resource "aws_s3_bucket_public_access_block" "terraform_state" {
bucket = aws_s3_bucket.terraform_state.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment