Manages environment-specific Terraform variables stored in AWS Secrets Manager.
Terraform tfvars files are stored in AWS Secrets Manager and downloaded locally before running Terraform commands.
Key Benefits:
- Centralized storage: Team members download from AWS instead of manual sharing
- No secrets in git: tfvars files are in
.gitignoreand never committed - Environment support: Separate secrets for production and beta
- Simple workflow: Download once, use with standard Terraform commands
# 1. Download tfvars from AWS (one time per environment)
./scripts/terraform/secrets.sh production
# 2. Run terraform commands - they use the downloaded file
./scripts/aws-deploy.sh plan production
./scripts/aws-deploy.sh apply productionDownload tfvars manually before running terraform commands.
| File | Purpose |
|---|---|
secrets.sh |
Manage tfvars: download (default), upload, and view |
Secrets are stored as raw tfvars file content in AWS Secrets Manager:
| Secret Name | Environment | Content |
|---|---|---|
tesslate/terraform/production |
Production | Raw content of terraform.production.tfvars |
tesslate/terraform/beta |
Beta | Raw content of terraform.beta.tfvars |
# Download production tfvars
./scripts/terraform/secrets.sh production
# Download beta tfvars
./scripts/terraform/secrets.sh beta
# This creates: k8s/terraform/aws/terraform.{env}.tfvars# After downloading, run terraform commands
./scripts/aws-deploy.sh plan production
./scripts/aws-deploy.sh apply production# Upload your local file to AWS
./scripts/terraform/secrets.sh upload production
# Now team members can download it# Download and save to local file
./scripts/terraform/secrets.sh download production
# Or use the shorter command
./scripts/terraform/secrets.sh production# View tfvars content from AWS without downloading
./scripts/terraform/secrets.sh view production# 1. Download latest version first (to avoid conflicts)
./scripts/terraform/secrets.sh production
# 2. Edit local file
vim k8s/terraform/aws/terraform.production.tfvars
# 3. Upload back to AWS
./scripts/terraform/secrets.sh upload production
# 4. Notify team to download latest- Go to AWS Secrets Manager console
- Find secret:
tesslate/terraform/{environment} - Click "Retrieve secret value"
- Click "Edit"
- Modify the tfvars content
- Click "Save"
Changes take effect immediately - team members just need to download latest.
# Upload to AWS Secrets Manager
./scripts/terraform/secrets.sh upload production
./scripts/terraform/secrets.sh upload beta
# Test downloading
./scripts/terraform/secrets.sh production
# Test terraform
./scripts/aws-deploy.sh plan production-
Create tfvars file locally:
vim k8s/terraform/aws/terraform.production.tfvars # Add all your variables: environment, domain_name, passwords, API keys, etc. -
Upload to AWS:
./scripts/terraform/secrets.sh upload production
-
Team members can now download:
./scripts/terraform/secrets.sh production
# Make changes locally
vim k8s/terraform/aws/terraform.production.tfvars
# Upload to AWS
./scripts/terraform/secrets.sh upload production
# Notify team in Slack/email:
# "Updated production secrets, please re-download:
# ./scripts/terraform/secrets.sh production"# Download latest secrets
./scripts/terraform/secrets.sh production
# Use terraform normally
./scripts/aws-deploy.sh plan production
./scripts/aws-deploy.sh apply productionThe AWS user/role needs:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue",
"secretsmanager:PutSecretValue",
"secretsmanager:CreateSecret",
"secretsmanager:DescribeSecret"
],
"Resource": "arn:aws:secretsmanager:us-east-1:*:secret:tesslate/terraform/*"
}
]
}The <AWS_IAM_USER> IAM user has these permissions.
Some variables must differ between environments. Key settings:
| Variable | Production | Beta | Purpose |
|---|---|---|---|
environment |
"production" |
"beta" |
Resource naming, image tags |
domain_name |
"opensail.tesslate.com" |
"your-domain.com" |
Application domain |
image_tag |
"production" |
"beta" |
Docker image tag pushed to ECR |
Note: ECR repositories are managed by the shared stack (k8s/terraform/shared/), not by environment stacks. See docs/infrastructure/terraform/ecr.md.
-
Never commit .tfvars files to git
- Already in
.gitignore:k8s/terraform/**/*.tfvars
- Already in
-
Download fresh copy before editing
- Prevents overwriting other team members' changes
-
Notify team after uploading changes
- So they download the latest version
-
Rotate sensitive values regularly
- Update locally, upload to AWS, team downloads latest
-
Use least-privilege IAM roles
- Grant secretsmanager access only to terraform users
-
Enable CloudTrail
- Audit who accessed/modified secrets and when
Install from: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
aws configure
# Or use environment variables:
export AWS_ACCESS_KEY_ID="your-key"
export AWS_SECRET_ACCESS_KEY="your-secret"
export AWS_REGION="us-east-1"# Upload it first
./scripts/terraform/secrets.sh upload productionVerify your AWS user has the required IAM permissions (see above).
# Download it from AWS
./scripts/terraform/secrets.sh production
# Or use aws-deploy.sh which downloads automatically
./scripts/aws-deploy.sh plan production-
Download tfvars from AWS Secrets Manager:
./scripts/terraform/secrets.sh production
-
File is saved to:
k8s/terraform/aws/terraform.production.tfvars -
Run terraform with the downloaded file:
./scripts/aws-deploy.sh plan production # Terraform uses: -var-file="terraform.production.tfvars" -
Local file persists - use it for multiple terraform commands until secrets change
-
Re-download when secrets are updated by team members
| Command | Purpose |
|---|---|
./scripts/terraform/secrets.sh {env} |
Download tfvars from AWS (default command) |
./scripts/terraform/secrets.sh download {env} |
Download tfvars from AWS (explicit) |
./scripts/terraform/secrets.sh upload {env} |
Upload local tfvars to AWS |
./scripts/terraform/secrets.sh view {env} |
View tfvars content in AWS |
./scripts/aws-deploy.sh plan {env} |
Plan changes (requires downloaded tfvars) |
./scripts/aws-deploy.sh apply {env} |
Apply changes (requires downloaded tfvars) |
- k8s/terraform/aws/README.md - Terraform deployment guide
- CLAUDE.md - Project documentation (see "Terraform Deployment & Configuration")
- scripts/aws-deploy.sh - Main deployment script
- QUICKSTART.md - Quick reference guide