diff --git a/Terraform-AWS-Services-Creation/1-Create-S3-Bucket-To-Store-TFSTATE-Files.md b/Terraform-AWS-Services-Creation/1-Create-S3-Bucket-To-Store-TFSTATE-Files.md index e964f03..bb8fe6d 100644 --- a/Terraform-AWS-Services-Creation/1-Create-S3-Bucket-To-Store-TFSTATE-Files.md +++ b/Terraform-AWS-Services-Creation/1-Create-S3-Bucket-To-Store-TFSTATE-Files.md @@ -12,6 +12,7 @@ The Terraform `main.tf` will do a few things: - Utilize AES256 encryption 2. Create the bucket by running the following: +- Adding a random number to the end of the bucket name in the main.tf file (as S3 bucket names must be globally unique) - `terraform init` - To initialize the working directory and pull down the provider - `terraform plan` - To go through a "check" and confirm the configurations are valid - `terraform apply - To create the resource \ No newline at end of file diff --git a/Terraform-AWS-Services-Creation/terraform-state-s3-bucket/main.tf b/Terraform-AWS-Services-Creation/terraform-state-s3-bucket/main.tf index cba9f7a..7e0b68f 100644 --- a/Terraform-AWS-Services-Creation/terraform-state-s3-bucket/main.tf +++ b/Terraform-AWS-Services-Creation/terraform-state-s3-bucket/main.tf @@ -3,16 +3,21 @@ provider "aws" { } resource "aws_s3_bucket" "terraform_state" { - bucket = "terraform-state-devopsthehardway" - versioning { - enabled = true + bucket = "terraform-state-devopsthehardwayXXXX" #Replace the XXXX with random digits (as S3 bucket names must be globally unique in AWS) +} + +resource "aws_s3_bucket_versioning" "terraform_state_versioning" { + bucket = aws_s3_bucket.terraform_state.id + versioning_configuration { + status = "Enabled" } +} - server_side_encryption_configuration { - rule { - apply_server_side_encryption_by_default { - sse_algorithm = "AES256" - } +resource "aws_s3_bucket_server_side_encryption_configuration" "terraform_state_encryption" { + bucket = aws_s3_bucket.terraform_state.id + rule { + apply_server_side_encryption_by_default { + sse_algorithm = "AES256" } } } \ No newline at end of file