Prerequisites
Before you begin, ensure you have:- Terraform
>= 1.5.7installed - AWS CLI configured with appropriate credentials
- An AWS account with permissions to create S3 buckets and IAM policies
Create your first bucket
Create your Terraform configuration
Create a new directory and a
main.tf file with the following content:main.tf
Initialize Terraform
Download the module and provider:You should see output confirming the module was downloaded from the Terraform Registry.
Preview the plan
Review what Terraform will create:Terraform will show you a plan to create an S3 bucket with versioning enabled and public access blocked by default.
Apply the configuration
Create the bucket:Type
yes when prompted. Terraform will create the bucket and output the bucket ID and ARN.Common configurations
Private bucket with versioning
The simplest production-ready configuration:Bucket for ELB access logs
Configure a bucket to receive Classic Load Balancer access logs:Bucket for ALB/NLB access logs
Configure a bucket to receive Application or Network Load Balancer logs:Bucket for WAF logs
Configure a bucket to receive AWS WAF logs:Available outputs
Afterterraform apply, the following outputs are available:
| Output | Description |
|---|---|
s3_bucket_id | The bucket name |
s3_bucket_arn | The bucket ARN |
s3_bucket_bucket_domain_name | bucketname.s3.amazonaws.com |
s3_bucket_bucket_regional_domain_name | Region-specific bucket domain name |
s3_bucket_hosted_zone_id | Route 53 Hosted Zone ID for the bucket’s region |
s3_bucket_region | The AWS region of the bucket |
s3_bucket_website_endpoint | Website endpoint (if website hosting is configured) |
s3_bucket_website_domain | Website domain (for Route 53 alias records) |
aws_s3_bucket_versioning_status | Versioning status: Enabled, Suspended, or Disabled |
Next steps
All input variables
Browse every configuration option with types and defaults.
Encryption guide
Configure SSE-S3 or SSE-KMS server-side encryption.
Security policies
Enforce TLS, block public access, and control encryption.
Full examples
Complete working configurations for every use case.

