Prompt
I need a recommendation for managing cloud infrastructure in code across dev, staging, and prod
Latest observation
A solid default recommendation is:
Use Infrastructure as Code with Terraform
For managing cloud infrastructure across dev, staging, and prod, Terraform is usually the best all-around choice because it:
- Works across major cloud providers
- Has a large ecosystem
- Supports modular, repeatable environments
- Handles environment separation well
- Is widely adopted and easy to hire for
Recommended setup
1. Separate environments clearly
Use one of these patterns:
- Separate state per environment
Best practice for most teams. - Separate accounts/subscriptions/projects per environment
Best for stronger isolation and safer prod controls.
A common structure:
devstagingprod
Each environment should have:
- its own state
- its own variables
- ideally its own cloud account or subscription
2. Use reusable modules
Create Terraform modules for shared components like:
- VPC/VNet
- Kubernetes clusters
- databases
- IAM roles
- load balancers
- monitoring
Then instantiate those modules per environment with different sizing and settings.
3. Keep environment-specific config minimal
Use:
dev.tfvarsstaging.tfvarsprod.tfvars
or separate folders per environment:
environments/devenvironments/stagingenvironments/prod
4. Put Terraform in CI/CD
Use pipelines to:
- run
terraform fmt terraform validateterraform plan- require review before
apply - restrict prod applies to approvals
5. Store state remotely
Use a remote backend:
- AWS S3 + DynamoDB
- Azure Storage
- GCS
- Terraform Cloud/Enterprise
This avoids local state files and makes collaboration safer.
Good operational practices
- Use least-privilege IAM
- Protect prod with manual approval gates
- Tag resources by environment
- Encrypt state and secrets
- Avoid hardcoding secrets in code
- Use separate service accounts/roles for each environment
If you want a simpler alternative
If your team is already heavily invested in a cloud-native ecosystem:
- AWS: CloudFormation or CDK
- Azure: Bicep
- GCP: Deployment Manager is less favored; Terraform is still common
But for multi-environment management, Terraform + CI/CD + separate state/accounts is the most practical recommendation.
Short recommendation
If you want one sentence:
Use Terraform with reusable modules, separate state and cloud accounts for dev/staging/prod, and manage changes through CI/CD with approval gates for production.
If you want, I can also recommend a specific folder structure, pipeline setup, or compare Terraform vs Pulumi vs CDK.