Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Terraform State S3 bucket resources to new format required in AWS Provider v4.0.0 #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 13 additions & 8 deletions Terraform-AWS-Services-Creation/terraform-state-s3-bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}