tfvars Documentation

Comprehensive guide to managing Terraform variable files for Discord infrastructure using tfvars. Includes setup, usage, and best practices.

Getting Started

Installation

Install tfvars-cli using your package manager:

npm install -g tf tfvars-cli

Verify the installation:

tfvars --version

Creating a tfvars File

Use the init command to generate a template:

tfvars init --env dev

This creates a configuration file structure with environment-specific subdirectories.

Configuration Examples

Basic Configuration

Example configuration for a Discord bot deployment:


# discord_bot.auto.tfvars
bot_token                = "your-token-here"
database_url             = "postgresql://..."
log_level                = "debug"
feature_flags            = {
  "use_cache"            = true
  "rate_limiting"        = true
  "metrics_exporter"     = false
}

Use secure values for sensitive information and follow security best practices for credentials management.

Environment-Specific Variables

Use the environment command to work with different configurations:


# Activate production configuration
tfvars environment production

# List active configuration
tfvars environment --list

Security Best Practices

Secrets Management

  • Never commit unencrypted secrets to version control
  • Use encrypted files for production credentials
  • Rotate secrets regularly with tfvars-rotate
tfvars-encrypt secrets.dev.tfvars

Audit and Validation

  • Run audits with tfvars-audit to find security issues
  • Use tfvars-validate to check for common syntax errors
  • Implement automated validation in your CI/CD pipelines
tfvars-audit --all

Need Help?