This document describes the recommended folder and repository structure for managing cloud infrastructure and applications using Terraform modules, a dedicated infrastructure repo, and a GitOps apps repo.
This repository contains reusable, versioned Terraform modules for networking, databases, Kubernetes clusters, and more. Each module is self-contained and documented.
terraform-modules/
├── README.md
├── vpc/
│ ├── main.tf
│ ├── variables.tf
│ ├── outputs.tf
│ └── README.md
├── rds/
│ ├── main.tf
│ ├── variables.tf
│ ├── outputs.tf
│ └── README.md
├── redis/
│ ├── main.tf
│ ├── variables.tf
│ ├── outputs.tf
│ └── README.md
└── ... (other modules as needed)
- Each directory under the root is a module (e.g.,
vpc,rds,redis). - Modules are referenced in other repos by their Git URL and path.
This repository is the source of truth for cloud infrastructure deployments. It references modules from terraform-modules and organizes infrastructure per environment (dev, prod, etc.).
devops-services/
├── README.md
├── environments/
│ ├── dev/
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ ├── vpc-app.tf
│ │ ├── vpc-redis.tf
│ │ ├── vpc-rds.tf
│ │ ├── rds.tf
│ │ ├── redis.tf
│ │ ├── kops-cluster.tf
│ │ ├── outputs.tf
│ │ └── ... (other infra files)
│ └── prod/
│ ├── main.tf
│ ├── variables.tf
│ ├── vpc-app.tf
│ ├── vpc-redis.tf
│ ├── vpc-rds.tf
│ ├── rds.tf
│ ├── redis.tf
│ ├── kops-cluster.tf
│ ├── outputs.tf
│ └── ... (other infra files)
└── modules/ (optional: for custom wrappers/compositions)
- Each environment is fully isolated in its own directory.
- References modules in
terraform-modulesviasource = "git::https://github.com/<org>/terraform-modules.git//vpc?ref=main"
This repository stores all application definitions, Kubernetes manifests, and GitOps configurations for each environment.
dc/
├── README.md
├── environments/
│ ├── dev/
│ │ ├── apps/
│ │ │ ├── website-deployment.yaml
│ │ │ ├── website-service.yaml
│ │ │ └── ... (other apps)
│ │ ├── kustomization.yaml
│ │ └── flux/
│ │ └── ... (Flux sync, sources, etc.)
│ └── prod/
│ ├── apps/
│ │ └── ... (prod app manifests)
│ ├── kustomization.yaml
│ └── flux/
└── clusters/
├── dev-k8s/
│ └── flux-system/
└── prod-k8s/
└── flux-system/
- Use Kustomize overlays or Helm charts for environment-specific configuration.
- Managed by Flux or Argo CD for continuous delivery to Kubernetes clusters.
terraform-modulesprovides reusable building blocks for infrastructure.devops-servicesassembles and deploys infrastructure using these modules, per environment.dcmanages application delivery to clusters created bydevops-services.
- All changes are made via pull requests for auditability and review.
- Use semantic versioning and tags for modules in
terraform-modules. - Integrate CI/CD for validating Terraform plans and Kubernetes manifests.
- Use clear documentation (
README.md) in every repo and module directory. - Separate secrets using tools like SOPS or SealedSecrets in the
dcrepo.
- Add/Update Module: Propose a change in
terraform-modulesvia PR, tag a release. - Infra Change: Update
devops-servicesto use/upgrade module, propose PR, review, and merge. - App Change: Update manifests in
dc, propose PR, review, and merge. Flux/Argo applies change.