Environment Templates

Templates define the structure of your environment variables without actual values. They help with:

  • Onboarding: New developers know exactly which variables they need
  • Documentation: Variable requirements are self-documenting
  • Validation: Ensure required variables are present before running

Template Formats

Simple Format (.env.template)

A basic format similar to .env files:

# Database
DATABASE_URL=          # Required - PostgreSQL connection string
DATABASE_POOL_SIZE=10  # Optional - defaults to 10

# API Keys
STRIPE_SECRET_KEY=     # Required
STRIPE_WEBHOOK_SECRET= # Required

# Feature Flags
ENABLE_ANALYTICS=true  # Optional - defaults to true

YAML Format (.env.template.yaml)

A structured format with metadata:

name: my-app
description: Environment template for My App

variables:
  - key: DATABASE_URL
    description: PostgreSQL connection string
    required: true
    secret: true
    
  - key: DATABASE_POOL_SIZE
    default: "10"
    description: Database connection pool size
    
  - key: STRIPE_SECRET_KEY
    required: true
    secret: true
    
  - key: LOG_LEVEL
    default: "info"
    description: Logging level (debug, info, warn, error)

Commands

init

Initialize a project with both configuration and template:

envmanager init --project <id>

This creates:

  • envmanager.json - Project configuration
  • .env.template - Environment template

Options:

OptionDescription
-p, --project <id>Project ID
-e, --environment <name>Environment to base template on
--format <type>Template format: simple or yaml
-f, --forceOverwrite existing files
# Initialize with YAML template
envmanager init --project abc123 --format yaml

# Initialize from production environment
envmanager init --project abc123 --environment production

template generate

Generate a template from current EnvManager variables:

envmanager template generate [options]

Options:

OptionDescription
-e, --environment <name>Environment to generate from
-o, --output <file>Output file (default: .env.template)
--format <type>Format: simple or yaml
-f, --forceOverwrite existing file
# Generate template from development
envmanager template generate

# Generate YAML template from production
envmanager template generate --environment production --format yaml

template sync

Sync template with EnvManager (add missing variables):

envmanager template sync [options]

Options:

OptionDescription
-i, --input <file>Template file (default: .env.template)
-e, --environment <name>Target environment
--dry-runShow what would be synced
# Preview sync
envmanager template sync --dry-run

# Sync to specific environment
envmanager template sync --environment staging

template validate

Validate that a .env file contains all required template variables:

envmanager template validate [options]

Options:

OptionDescription
-t, --template <file>Template file (default: .env.template)
-i, --input <file>Env file to validate (default: .env)
# Validate .env against template
envmanager template validate

# Validate specific files
envmanager template validate --template .env.template.yaml --input .env.local

Output:

Validating .env against .env.template

Missing required variables:
  - STRIPE_SECRET_KEY
  - DATABASE_URL

Variables with default values (using defaults):
  - LOG_LEVEL (default: info)
  - DATABASE_POOL_SIZE (default: 10)

Validation failed: 2 required variables missing

Workflows

New Project Setup

  1. Project owner creates variables in EnvManager
  2. Generate template and commit to repo:
    envmanager template generate
    git add .env.template
    git commit -m "Add environment template"
    

New Developer Onboarding

  1. Clone the repo
  2. Review required variables in template:
    cat .env.template
    
  3. Request access to EnvManager project
  4. Pull variables:
    envmanager login
    envmanager pull
    

CI/CD Validation

Add to your pipeline:

# GitHub Actions example
- name: Validate environment
  run: envmanager template validate
  env:
    ENVMANAGER_API_KEY: ${{ secrets.ENVMANAGER_API_KEY }}

Keeping Templates Updated

When adding new variables:

  1. Add to EnvManager via web UI
  2. Regenerate template:
    envmanager template generate --force
    git add .env.template
    git commit -m "Update environment template"
    

Or sync from template to EnvManager:

  1. Edit .env.template manually
  2. Sync to EnvManager:
    envmanager template sync
    

Get DevOps tips in your inbox

Security best practices and product updates. No spam.

No spam. Unsubscribe anytime.