Created
March 31, 2023 20:58
-
-
Save shollingsworth/1bb7b78e5fa20bfe55a28b91904b42ae to your computer and use it in GitHub Desktop.
Starter main.tf for terraform state files only in AWS using s3 bucket and dynamoDB
This file contains hidden or 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 = "us-east-2" | |
| default_tags { | |
| tags = { | |
| tag1 = "value1" | |
| tag2 = "value2" | |
| } | |
| } | |
| } | |
| resource "aws_s3_bucket" "terraform_state" { | |
| bucket = "dest-bucket-name" | |
| # Prevent accidental deletion of this S3 bucket | |
| lifecycle { | |
| prevent_destroy = true | |
| } | |
| } | |
| resource "aws_s3_bucket_versioning" "enabled" { | |
| bucket = aws_s3_bucket.terraform_state.id | |
| versioning_configuration { | |
| status = "Enabled" | |
| } | |
| } | |
| resource "aws_s3_bucket_server_side_encryption_configuration" "default" { | |
| bucket = aws_s3_bucket.terraform_state.id | |
| rule { | |
| apply_server_side_encryption_by_default { | |
| sse_algorithm = "AES256" | |
| } | |
| } | |
| } | |
| resource "aws_s3_bucket_public_access_block" "public_access" { | |
| bucket = aws_s3_bucket.terraform_state.id | |
| block_public_acls = true | |
| block_public_policy = true | |
| ignore_public_acls = true | |
| restrict_public_buckets = true | |
| } | |
| resource "aws_dynamodb_table" "terraform_locks" { | |
| name = "dest-state-lock" | |
| 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