This directory contains environment-specific configurations for deploying Oshun infrastructure to different environments (staging, production).
Structure#
text
environments/
├── staging/ # Staging environment
│ ├── backend.tf # S3 backend config for staging state
│ ├── main.tf # Module references and providers
│ ├── outputs.tf # Environment outputs
│ ├── variables.tf # Variable definitions
│ └── terraform.tfvars.example # Example values (copy to terraform.tfvars)
├── production/ # Production environment
│ ├── backend.tf # S3 backend config for production state
│ ├── main.tf # Module references and providers
│ ├── outputs.tf # Environment outputs
│ ├── variables.tf # Variable definitions
│ └── terraform.tfvars.example # Example values (copy to terraform.tfvars)
└── README.md # This file
Usage#
Initial Setup#
-
Ensure the state backend is deployed first:
bashcd ../state-backend terraform init terraform apply -
Copy the example tfvars file:
bashcd environments/staging # or production cp terraform.tfvars.example terraform.tfvars # Edit terraform.tfvars with your specific values -
Initialize the environment:
bashterraform init
Planning Changes#
bash
cd environments/staging
terraform plan
Applying Changes#
bash
cd environments/staging
terraform apply
Environment Isolation#
Each environment has:
- Separate state file in S3 with environment-specific key
- Separate DynamoDB lock to prevent concurrent modifications
- Environment-specific variables for sizing, redundancy, and features
Key Differences#
| Feature | Staging | Production |
|---|---|---|
| Instance sizes | Small (cost-opt) | Large (performance) |
| Multi-AZ | Disabled | Enabled |
| Deletion protection | Disabled | Enabled |
| Backup retention | 7 days | 30 days |
| Monitoring | Basic | Enhanced |
| Alerting | Slack only | PagerDuty + Slack |
CI/CD Integration#
The GitHub Actions workflow in .github/workflows/terraform.yml:
- Detects changes in
infra/terraform/ - Runs
terraform planfor changed modules - Posts plan output as PR comment
- On merge to main:
- Auto-applies to staging
- Requires approval for production