Mono Repo Terraform Layout [highly opinionated]. Based on Vanilla Terraform, this layout used in Terminal or CI/CD operations, and Terraform Cloud.
Alert!: There are quite few ways/tools to layout your Infrastructure as code. this is for plain vanilla Terraform.This repo contains several distinct folders each with specific purpose, and it expected to run in order.
- bootstrap: contains Terraform bootstrap for:
- AWS [option 1] (S3 bucket, KMS key and Dynamodb table for State files) - generate state file template for each environment.
- TFC [option 2] (Terraform Cloud workspaces - Organization - environment variables) - generate state file template for each environment.
- Github ( Repos - Access - Actions - Tokens) - generate two [minimum] repositories:
iac-terraform-templatesiac-terraform-modules
- docs: Documentations, screenshots and diagrams related files, alongside development workflow, includes
drawiofile. - stacks: Terraform templates that define a working unit, consist of static and dynamic infrastructure, including:
appstack [dynamic] [target one or more account]: application related, mainly dynamic infrastructure.datastack [static] [target one or more account]: databases, cache, s3 buckets, and data related.networkstack [static] [target one or more account]: networking, DNS, and VPN.mgmtstack [static] [target one account]: management related, SSO.secstack [static] [target one account]: security related.
- envs: contains environments [dev-stage-prod][mgmt-sec] and regions including:
region.tfvarscommon environment valuesnetwork.tfvarsnetwork stack valuesdata.tfvarsdata stack valuesapp.tfvarsapp stack valuesnetwork.hclnetwork stack state file blockdata.hcldata stack state file blockapp.hclapp stack state file block.envenvironment secrets and Cloud Access
- Taskfile.yml:
Taskfileorchestrator for operations, includes other task files fromtasksfolder. - tasks: Taskfile files - added as
submodulefrom https://github.com/mhmdio/iac-taskfile-framework - CODEOWNERS: Code owners for automate PR assignments.
- bootstrap: creates backends, workspaces and repos
- envs/mgmt: creates organization, accounts and SSO
- envs/ENV/REGION/network: creates networking and VPN.
- envs/ENV/REGION/data: creates databases, caches and S3 buckets.
- envs/ENV/REGION/app: creates dynamic App Infra.
- modules [optional][use another monoRepo for modules]: custom Terraform modules folder, use public well-trusted modules, use https://github.com/mhmdio/terraform-module-base for module template.
- config [optional]: config files for all 3rd party tools that used with Terraform, and pipelines
CI/CDsamples files for automate Terraform Operations. - helm [optional]:
helmandhelmfile. - serverless [optional]:
Serverlessframework to manage Dynamic infrastructure - policies [optional]:
OPApolicies. - tests [optional]: test implementation using
LocalStackandconftest - DevOps..sh [optional]:
Bashscript orchestrator for operations. - Makefile [optional]:
Makefileorchestrator for operations, check https://github.com/mhmdio/iac-makefile-framework for more Make files. - Dockerfile [optional]:
Dockerfileto build an image with all tools needed for development.
- Taskfile
- Git
- Docker
- terraform
- terraform-docs
- terraform-lsp
- atlantis
- infracost
- inframap
- tflint
- driftctl
- tfsec
- checkov
- cloudrail
- KICS
- OPA
- kubectl
- helm
- helmfile
- awscli
- aws-vault
- direnv
- drawio
- VSCode
- Lens
