Terraform AWS S3 Bucket Config Builder
Terraform lets you define cloud infrastructure as version-controlled code. This builder generates HCL for an AWS S3 bucket using the modern resource layout, where versioning, encryption, public access, and lifecycle are separate resources that all reference the core bucket. It produces a secure-by-default configuration you can drop into a Terraform module.
How it works
The output defines an aws_s3_bucket resource, then attaches companion resources by referencing its id:
aws_s3_bucket_versioningtoggles object versioning.aws_s3_bucket_server_side_encryption_configurationsets the SSE algorithm (AES256oraws:kms).aws_s3_bucket_public_access_blocksets all four block flags to true.aws_s3_bucket_lifecycle_configurationexpires objects after N days when enabled.
This split layout is required by AWS provider v4 and later, where the single all-in-one aws_s3_bucket block was deprecated.
Tips and example
Run the standard workflow after copying the HCL:
terraform init
terraform plan
terraform apply
Always keep public access blocking on unless you are intentionally hosting a public website. For compliance workloads, prefer aws:kms with a dedicated KMS key so access is logged in CloudTrail. Use lifecycle expiration on log or temp buckets to keep storage costs predictable.