Last active
December 4, 2020 21:12
-
-
Save Staggerlee011/b08b80dad659cd549030e5855a798673 to your computer and use it in GitHub Desktop.
Terraform template to create a secure s3 bucket, dnamodb for state file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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