atmos.GomplateDatasource
Stop hardcoding values in your infrastructure configurations. The atmos.GomplateDatasource
function lets you pull live data from anywhere - APIs, cloud services, databases, files - directly into your Atmos stacks. Instead of manually updating IP addresses, account IDs, or configuration values, your infrastructure can fetch them automatically at runtime. Plus, with built-in caching, it's lightning fast even when you reference the same data hundreds of times.
What are Datasources?​
Think of datasources as live connections to your data, wherever it lives. Instead of copying and pasting values into your configurations (and keeping them updated), datasources let Atmos fetch the latest data automatically when it runs.
The Problem: Traditional infrastructure configurations require you to:
- Hardcode values that change (IP addresses, account IDs, API keys)
- Manually update configurations when external systems change
- Duplicate data across multiple files
- Risk using outdated or incorrect values
The Solution: Datasources let you:
- Pull live data from any API, database, or cloud service
- Stay synchronized with external systems automatically
- Centralize configuration in its proper home (not in your IaC)
- Access secrets securely from vaults without exposing them
- Query cloud metadata like account IDs, regions, or resource tags dynamically
Real-World Example​
Without Datasources (Manual, Error-Prone):
components:
terraform:
vpc:
vars:
account_id: "123456789012" # Hardcoded - wrong in other environments!
allowed_ip: "203.0.113.45" # Bob's IP - outdated when he moves
db_password: "prod-pass-123" # SECURITY RISK! Password in git
With Datasources (Dynamic, Secure):
components:
terraform:
vpc:
vars:
account_id: '{{ (atmos.GomplateDatasource "aws").account_id }}'
allowed_ip: '{{ (atmos.GomplateDatasource "myip").ip }}'
db_password: '{{ (atmos.GomplateDatasource "vault").database.password }}'
Common Use Cases​
- Service Discovery: Query current IP addresses, endpoints, or service locations
- Dynamic Configuration: Fetch configuration values from external systems
- Secret Management: Retrieve secrets from HashiCorp Vault, AWS Secrets Manager, etc.
- Metadata Queries: Get AWS account info, region data, or resource tags
- External Data Import: Load data from CSV files, JSON APIs, or databases
Usage​
{{ (atmos.GomplateDatasource "<alias>").<attribute> }}
Arguments​
alias
- The datasource alias defined in your Atmos configuration
attribute
- Attribute name (field) to extract from the datasource response
Supported Datasource Types​
Gomplate supports numerous datasource types:
- HTTP/HTTPS: REST APIs and web services
- File: Local files (JSON, YAML, TOML, CSV, etc.)
- AWS: Systems Manager Parameter Store, Secrets Manager, S3
- Cloud: Azure Key Vault, Google Cloud Storage
- Vault: HashiCorp Vault secrets
- Environment: Environment variables
- Git: Git repository data
- Consul: HashiCorp Consul key-value store
How it Works​
Automatic Caching​
The atmos.GomplateDatasource
function automatically caches results in memory during stack processing:
- First call: Fetches data from the external source and stores in cache
- Subsequent calls: Returns cached data without additional external calls
- Cache scope: Per Atmos execution (cache is cleared between runs)
This caching mechanism provides several benefits:
- Performance: Dramatically faster stack processing with multiple datasource references
- Reliability: Reduces failures from rate limiting or network issues
- Cost savings: Fewer API calls to metered services
- Consistency: All references get the same data within a single execution
Comparison with Direct Gomplate Datasources​
Feature | datasource (Gomplate) | atmos.GomplateDatasource |
---|---|---|
External calls | Every invocation | Once per alias |
Performance | Slower with multiple uses | Fast (cached) |
Rate limiting risk | High | Low |
Network failures | Each call can fail | Single point of failure |
Use case | Single reference | Multiple references |
Examples​
Basic API Call​
AWS Systems Manager Parameter​
Loading External Configuration​
Performance Example​
Consider this configuration that references the same datasource multiple times:
Without caching: 5 API calls (potential for timeouts, rate limiting)
With atmos.GomplateDatasource
: 1 API call (4 cache hits)
Best Practices​
- Always use
atmos.GomplateDatasource
for repeated references to the same external data - Configure appropriate timeouts in the
gomplate.timeout
setting - Handle errors gracefully - external sources can fail
- Use caching strategically - cache expensive or rate-limited APIs
- Document your datasources - explain what external data is being fetched and why