Skip to content

Latest commit

Β 

History

272 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🚧 Terraform Project Template

Documentation

This repository provides a structured template for Terraform projects, enabling consistent and scalable infrastructure deployments. The template has best practices, CI/CD integration, and environment-specific configurations to streamline infrastructure management.

πŸ“ Repository Structure

.
β”œβ”€β”€ backend.tf                          # πŸ”§ Defines the backend configuration for Terraform
β”œβ”€β”€ CHANGELOG.md                        # πŸ“ Change log of the project
β”œβ”€β”€ .checkov.yml                        # πŸ”’ Configuration file for Checkov security scanner
β”œβ”€β”€ CODEOWNERS                          # πŸ‘₯ Defines the code owners for the repository
β”œβ”€β”€ .devcontainer                       # 🐳 Development container configuration
β”‚   β”œβ”€β”€ devcontainer.json               # πŸ“¦ Devcontainer configuration file
β”‚   └── Dockerfile                      # πŸ‹ Dockerfile for the dev environment
β”œβ”€β”€ .editorconfig                       # πŸ–ŠοΈ Configuration for consistent coding styles
β”œβ”€β”€ environments                        # 🌍 Holds environment-specific variables
β”‚   β”œβ”€β”€ dev
β”‚   β”‚   └── dev.tfvars                  # πŸ› οΈ Development environment variables
β”‚   β”œβ”€β”€ prod
β”‚   β”‚   └── prod.tfvars                 # πŸš€ Production environment variables
β”‚   └── qa
β”‚       └── qa.tfvars                   # πŸ” QA environment variables
β”œβ”€β”€ .github                             # πŸ› οΈ GitHub-specific configurations
β”‚   β”œβ”€β”€ dependabot.yml                  # πŸ€– Dependabot configuration
β”‚   β”œβ”€β”€ ISSUE_TEMPLATE                  # πŸ“ GitHub issue template
β”‚   β”‚   └── issue_template.md           # πŸ“ Issue template file
β”‚   β”œβ”€β”€ pull_request_template.md        # πŸ“ Pull request template
β”‚   └── workflows                       # βš™οΈ GitHub Actions workflows
β”‚       β”œβ”€β”€ lint-pr.yaml                # 🧹 Linting workflow for pull requests
β”‚       β”œβ”€β”€ pre-commit-auto-update.yaml # πŸ”„ Pre-commit hook auto-update workflow
β”‚       β”œβ”€β”€ release.yaml                # πŸš€ Release workflow
β”‚       β”œβ”€β”€ stale.yaml                  # ⏳ Stale issue management workflow
β”‚       β”œβ”€β”€ template-repo-sync.yaml     # πŸ”„ Template repository sync workflow
β”‚       └── terraform-aws.yml           # ☁️ Terraform AWS workflow
β”œβ”€β”€ .gitignore                          # 🚫 Files and directories to be ignored by Git
β”œβ”€β”€ LICENSE                             # βš–οΈ License for the project
β”œβ”€β”€ locals.tf                           # πŸ› οΈ Local variables for Terraform
β”œβ”€β”€ main.tf                             # 🌐 Main Terraform configuration
β”œβ”€β”€ modules                             # πŸ“¦ Custom Terraform modules
β”‚   └── s3-bucket
β”‚       β”œβ”€β”€ main.tf                     # 🌐 Main configuration for s3-bucket
β”‚       β”œβ”€β”€ outputs.tf                  # πŸ“€ Output definitions for s3-bucket
β”‚       └── variables.tf                # πŸ“₯ Input variables for s3-bucket
β”œβ”€β”€ .pre-commit-config.yaml             # πŸ› οΈ Pre-commit hooks configuration
β”œβ”€β”€ providers.tf                        # ☁️ Provider configurations for Terraform
β”œβ”€β”€ README.md                           # πŸ“– Project documentation (this file)
β”œβ”€β”€ .releaserc.json                     # πŸš€ Semantic release configuration
β”œβ”€β”€ .terraform.lock.hcl                 # πŸ”’ Terraform lock file
β”œβ”€β”€ .tflint.hcl                         # πŸ› οΈ Terraform linting configuration
β”œβ”€β”€ variables.tf                        # πŸ“₯ Input variables for the project
└── .vscode                             # πŸ–₯️ VSCode-specific configurations
    └── extensions.json                 # πŸ› οΈ Recommended extensions for VSCode

πŸš€ Getting Started

🧰 Prerequisites

  • Terraform: Ensure you have Terraform installed.
  • Docker: Required for the development container setup.
  • VSCode: Recommended for development, with the Dev Containers extension.

πŸ–₯️ Development Environment

To get started with development, you can use the pre-configured development container:

  1. Open in VSCode:
  • Install the Dev Containers extension.
  • Open the repository in VSCode.
  • You should see a prompt to reopen the project in the dev container.
  1. Build and Run:
  • The dev container is pre-configured with all the necessary tools and extensions.
  • You can start writing and testing your Terraform configurations immediately.

πŸ› οΈ Terraform Configuration

  • Backend Configuration: The backend.tf file configures the remote state storage for Terraform.
  • Environment Variables: The environments/ directory contains environment-specific variable files (.tfvars).
  • Modules: Reusable Terraform modules are stored in the modules/ directory.

βœ… Pre-Commit Hooks

Pre-commit hooks are set up to ensure code quality and consistency. To install the pre-commit hooks:

pre-commit install

βš™οΈ Semantic Commit Messages

This project uses Semantic Commit Messages to ensure meaningful and consistent commit history. The format is as follows:

<type>(<scope>): <subject>

Types

  • feat: A new feature (e.g., feat: add login functionality).
  • fix: A bug fix (e.g., fix: resolve login button issue).
  • docs: Documentation changes (e.g., docs: update API documentation).
  • style: Code style changes (formatting, missing semi-colons, etc.) without changing logic (e.g., style: fix indentation).
  • refactor: Code changes that neither fix a bug nor add a feature (e.g., refactor: update user controller structure).
  • test: Adding or updating tests (e.g., test: add unit tests for login service).
  • chore: Changes to build process, auxiliary tools, or libraries (e.g., chore: update dependencies).

Scope

Optional: The part of the codebase affected by the change (e.g., feat(auth): add OAuth support)

Subject

A brief description of the change, using the imperative mood (e.g., fix: resolve issue with user authentication).

πŸš€ Semantic Release

This project is configured with Semantic Release to automate the release process based on your commit messages.

How It Works

  1. Analyze commits: Semantic Release inspects commit messages to determine the type of changes in the codebase.
  2. Generate release version: Based on the commit type, it will automatically bump the version following semantic versioning:
  • fix β†’ Patch release (e.g., 1.0.1)
  • feat β†’ Minor release (e.g., 1.1.0)
  • BREAKING CHANGE β†’ Major release (e.g., 2.0.0)
  1. Create release notes: It generates a changelog from the commit messages and includes it in the release.
  2. Publish: It automatically publishes the new version to the repository (and any other configured registries, e.g., npm).

🀝 Contributing

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Submit a pull request with a detailed description of the changes.

πŸ“œ License

This project is licensed under the MIT License.

Requirements

Name Version
terraform >= 1.0
aws ~> 5.0

Providers

Name Version
aws 5.95.0

Modules

No modules.

Resources

Name Type
aws_caller_identity.current data source

Inputs

Name Description Type Default Required
env The environment to deploy the resources string n/a yes
prefix The prefix for all resource's names string "dev" no
region The region to deploy the resources string "ap-southeast-1" no

Outputs

Name Description
environment The environment name
region The AWS region where resources are deployed
resource_prefix The prefix used for resource naming

About

Production-ready Terraform template for AWS with CI/CD, security scanning, and best practices

Resources

Contributing

Security policy

Stars

3 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages