Build a modular cloud environment with CI/CD.
Bring reusable Terraform modules, automated checks, secure credentials and approval-gated deployments together in a controlled infrastructure delivery workflow.
Understand the delivery architecture
Terraform code is reviewed and tested before a protected pipeline applies approved changes to AWS.
Git commit / pull request
Versioned Terraform code
Format · Validate · Test
Scan · Policy · Review
Reviewed change proposal
Authorized promotion
Before you start
Organize the project
terraform-advanced-cicd/ ├── modules/ │ ├── network/ # VPC, subnet, routes, gateway │ └── workload/ # security group and EC2 instance ├── environments/ │ ├── dev/ # root module + dev backend │ └── prod/ # isolated prod root + backend ├── .github/workflows/ │ └── terraform.yml # CI checks and gated deployment └── README.md
Each environment is a separate root configuration with its own backend key and variable values. Reusable modules contain resource definitions but do not configure the backend.
Explore the Terraform modules
Review the network and workload modules, then see how an environment root calls them.
Build the CI/CD workflow
A safe pipeline separates validation and planning from the protected apply stage.
Checks to include before deployment
- Formatting and validation
- Reusable module input validation
- Plan review and drift checks
- Static infrastructure scanning
- Least-privilege IAM and OIDC
- Encrypted, private remote state
- Protected branches and reviews
- Approval before production apply
- Deployment logs and rollback plan
Run the workflow locally first
Before connecting automation, confirm the development environment works from your terminal.
cd environments/dev terraform init terraform fmt -recursive terraform validate terraform plan -out=tfplan terraform show tfplan # Apply only after reviewing the plan: terraform apply tfplan
terraform plan -destroy terraform destroy
- Confirm VPC, subnet, route and workload resources match the approved plan.
- Confirm the workload is reachable only through the intended security group rules.
- Check pipeline logs and verify the exact commit and plan that were applied.
- Destroy lab resources when finished and retain or archive state according to your policy.
Test your understanding
From writing infrastructure to operating it safely.
Next, extend the lab with multiple Availability Zones, private workload placement, centralized logging, policy-as-code, automated tests and controlled promotion across accounts.