|
| 1 | +// Example: Complete secrets workflow |
| 2 | +// |
| 3 | +// This demonstrates the difference between: |
| 4 | +// 1. Pre-loaded env vars (comet.yaml) - needed BEFORE parsing |
| 5 | +// 2. Stack-level secrets - loaded DURING parsing, used by Terraform |
| 6 | + |
| 7 | +// ============================================================ |
| 8 | +// In comet.yaml: |
| 9 | +// ============================================================ |
| 10 | +// env: |
| 11 | +// # SOPS AGE key must be available before stack parsing |
| 12 | +// SOPS_AGE_KEY: op://ci-cd/sops-age-key/private |
| 13 | +// |
| 14 | +// # Any other early-stage environment variables |
| 15 | +// TF_LOG: DEBUG |
| 16 | +// ============================================================ |
| 17 | + |
| 18 | +stack({ |
| 19 | + name: 'complete-secrets-example', |
| 20 | + backend: { |
| 21 | + type: 'gcs', |
| 22 | + bucket: 'my-terraform-state', |
| 23 | + prefix: 'complete-example' |
| 24 | + } |
| 25 | +}) |
| 26 | + |
| 27 | +// Now that SOPS_AGE_KEY is set, we can use sops:// references |
| 28 | +component('database', { |
| 29 | + source: './modules/database', |
| 30 | + vars: { |
| 31 | + // SOPS secret (requires SOPS_AGE_KEY from comet.yaml) |
| 32 | + admin_password: secret('sops://secrets/db.yaml#admin_password'), |
| 33 | + |
| 34 | + // 1Password secret (loaded on-demand during stack parsing) |
| 35 | + backup_credentials: secret('op://production/database/backup-key'), |
| 36 | + |
| 37 | + // Plain values work too |
| 38 | + database_name: 'myapp_production' |
| 39 | + } |
| 40 | +}) |
| 41 | + |
| 42 | +component('app', { |
| 43 | + source: './modules/app', |
| 44 | + vars: { |
| 45 | + // Mix and match secret sources |
| 46 | + api_key: secret('sops://secrets/app.yaml#api_key'), |
| 47 | + oauth_client_secret: secret('op://production/oauth/client-secret'), |
| 48 | + |
| 49 | + // Reference outputs from other components |
| 50 | + database_host: state('database', 'host'), |
| 51 | + database_port: state('database', 'port') |
| 52 | + }, |
| 53 | + envs: { |
| 54 | + // Environment variables for Terraform execution |
| 55 | + TF_VAR_region: 'us-west-2' |
| 56 | + } |
| 57 | +}) |
0 commit comments