atmos terraform generate files
Use this command to generate auxiliary configuration files for Terraform components based on the generate section in stack configuration.
Usage
Execute the terraform generate files command like this:
# Generate files for a single component
atmos terraform generate files <component> -s <stack>
# Generate files for all components
atmos terraform generate files --all
This command generates files from the generate section of component configurations. Files are created in the component directory with content serialized based on file extension or processed as Go templates.
Run atmos terraform generate files --help to see all the available options
Examples
# Generate files for a single component in a stack
atmos terraform generate files vpc -s prod-ue2
# Generate files for all components across all stacks
atmos terraform generate files --all
# Preview what would be generated without writing files
atmos terraform generate files vpc -s prod-ue2 --dry-run
# Generate files for specific stacks only
atmos terraform generate files --all --stacks="prod-*"
# Generate files for specific components only
atmos terraform generate files --all --components="vpc,eks"
# Delete generated files
atmos terraform generate files --all --clean
Configuration
The generate section is defined at the component level in stack configuration:
components:
terraform:
vpc:
vars:
environment: prod
generate:
# Map values are serialized based on file extension
locals.tf:
locals:
environment: "{{ .vars.environment }}"
# String values are treated as Go templates
README.md: |
# VPC Component
Environment: {{ .vars.environment }}
Extension-Aware Serialization
.jsonfiles are serialized as JSON with 2-space indentation.yamland.ymlfiles are serialized as YAML with 2-space indentation.tfand.hclfiles generate valid HCL- Other extensions default to JSON
Template Context
String values and map string values are processed as Go templates with access to:
.vars- Component variables.settings- Component settings.env- Component environment variables.backend- Backend configuration.backend_type- Backend type.providers- Provider configurations.metadata- Component metadata.namespace,.tenant,.environment,.stage,.region- Context variables.atmos_component- Atmos component name.atmos_stack- Atmos stack name.component- Final component name.workspace- Terraform workspace
Auto-Generation
Enable automatic file generation during terraform commands:
# atmos.yaml
components:
terraform:
auto_generate_files: true
Configure File Generation
Learn how to configure the generate section in your stack manifests to create auxiliary files for Terraform components.
Arguments
component(optional)Atmos terraform component. Required when not using
--all.
Flags
--stack(alias-s)Atmos stack. Required when specifying a component.
--allProcess all components in all stacks. Cannot be used with a component argument.
atmos terraform generate files --all--stacksFilter stacks by glob pattern. Only used with
--all.atmos terraform generate files --all --stacks="prod-*"--componentsFilter components by comma-separated list. Only used with
--all.atmos terraform generate files --all --components="vpc,eks"--dry-runShow what would be generated without writing files.
atmos terraform generate files vpc -s prod-ue2 --dry-run--cleanDelete generated files instead of creating them.
atmos terraform generate files --all --clean