A modern infrastructure as code project for AWS S3 and CloudFront integration using Terraform.
| Tech Stack | Features | Prerequisites |
|---|---|---|
| Setup | Project Structure | Environment Variables |
-
Multi-Environment Support:
- Dynamic S3 bucket naming based on workspace
- Environment-specific configurations
- Context tagging for resource identification
-
AWS S3 Configuration:
- Automated bucket creation
- Static website hosting
- Custom error/index documents
- Resource tagging
- Environment-based isolation
-
CloudFront Integration:
- CDN distribution setup
- HTTPS redirection
- Custom origin configuration
- Global content delivery
- Price class management
-
Infrastructure Management:
- Terraform state management
- AWS provider configuration
- Data source integration
- Module-based architecture
- Terraform 1.0+
- AWS CLI configured
- AWS account with appropriate permissions
- Basic understanding of S3 and CloudFront concepts
- Clone the repository:
git clone https://github.com/yourusername/terraform-aws-infra.git
cd terraform-aws-infra- Initialize Terraform:
terraform init- Select workspace (environment):
terraform workspace select dev # or prod- Plan the infrastructure:
terraform plan- Apply the configuration:
terraform applyWe follow the Conventional Commits specification. Every commit message must follow this pattern:
<type>(<scope>): <description>
[optional body]
[optional footer(s)]feat: A new featurefix: A bug fixdocs: Documentation only changesstyle: Changes that do not affect the meaning of the coderefactor: A code change that neither fixes a bug nor adds a featureperf: A code change that improves performancetest: Adding missing tests or correcting existing testschore: Changes to the build process or auxiliary tools
infra: Changes to infrastructure configurations3: Changes related to S3 modulecdn: Changes related to CloudFront moduledocs: Changes to documentationci: Changes to CI/CD pipeline
# Feature example
feat(s3): add website hosting configuration
- Add index.html configuration
- Configure error document
- Enable static website hosting# Fix example
fix(cdn): correct origin protocol policy
- Update protocol policy to http-only
- Fix SSL protocols configuration# Documentation example
docs(readme): update project documentation
- Add commit convention section
- Update prerequisites
- Include contribution guidelines- Update the README.md with details of changes if needed
- Update the version numbers in files following SemVer
- Create your PR with a clear title and description
- Wait for review and approval from maintainers
terraform-aws-infra/
βββ main.tf # Main configuration file
βββ providers.tf # AWS provider configuration
βββ output.tf # Output definitions
βββ modules/
β βββ s3/ # S3 bucket module
β β βββ main.tf # S3 bucket configuration
β β βββ variables.tf # Module variables
β β βββ outputs.tf # Module outputs
β β βββ datasources.tf # S3 data sources
β βββ cloudfront/ # CloudFront module
β βββ main.tf # CloudFront configuration
β βββ variables.tf # Module variables
β βββ outputs.tf # Module outputs
β βββ datasources.tf # CloudFront data sources
βββ .gitignore # Git ignore rules
# AWS Configuration
AWS_ACCESS_KEY_ID="your-access-key"
AWS_SECRET_ACCESS_KEY="your-secret-key"
AWS_REGION="your-region"After applying the infrastructure, you'll get:
- S3 bucket domain name
- CloudFront distribution domain name
- CloudFront distribution ID
