Stack Names
Every stack in Atmos has a logical name used for identification, the -s flag, dependencies, and Terraform workspaces.
You can either set this name explicitly using the name field in your stack manifest, or compute it programmatically
using name_template in atmos.yaml.
Choosing Your Approach
Atmos offers two approaches for stack naming. Choose based on your infrastructure's consistency:
| Approach | Where | When to Use |
|---|---|---|
name_template | atmos.yaml | Consistent context variables across all stacks |
name | Stack manifest | Inconsistent naming, migrations, or legacy infrastructure |
Use name_template When
You should use name_template in atmos.yaml when:
- You have consistent context variables (like
namespace,tenant,environment,stage) across all stacks - All your root modules use these variables deterministically
- You want programmatic, convention-based naming (e.g., following the null-label pattern)
atmos.yaml
With this configuration, a stack with vars.tenant: acme, vars.environment: ue1, and vars.stage: prod will automatically be named acme-ue1-prod.
Use name When
You should use the name field in your stack manifest when:
- You're migrating from Terragrunt or another tool and need to preserve existing workspace names
- Your infrastructure has inconsistent naming that doesn't follow a pattern
- You have legacy stacks that predate your naming conventions
- You need to match existing Terraform workspace names exactly
- Any inconsistency in your vars would break a deterministic template
stacks/legacy-prod.yaml
With this configuration, the stack is identified as my-legacy-prod-stack regardless of the filename or any name_template in atmos.yaml.
Precedence Order
When determining a stack's name, Atmos uses this precedence order:
name(highest) - Explicit name from stack manifestname_template- Go template fromatmos.yamlname_pattern- Token-based pattern fromatmos.yaml- Default - Basename of the stack file (e.g.,
prod.yaml→prod)
This means the name field always wins, allowing you to override programmatic naming for specific stacks.
Configuration
The name field is a top-level key in stack manifests, at the same level as import, vars, and components:
name: "explicit-stack-name"
import:
- catalog/base
vars:
environment: prod
components:
terraform:
vpc:
vars:
cidr: "10.0.0.0/16"
Examples
Migrating from Terragrunt
When migrating from Terragrunt, your existing Terraform state is tied to specific workspace names. Use name to preserve these:
stacks/us-east-1/prod/vpc.yaml
This ensures atmos terraform apply vpc -s prod-us-east-1-vpc uses the existing state without requiring state migrations.
Legacy Infrastructure
For infrastructure that predates your naming standards:
stacks/old-datacenter.yaml
Mixed Approach
You can use name_template for most stacks while overriding specific ones with name:
atmos.yaml
stacks/acme/prod/us-east-1.yaml
stacks/legacy-acquisition.yaml
How Stack Names Are Used
Stack names appear throughout Atmos:
- CLI:
atmos terraform apply vpc -s my-stack-name - Listing:
atmos list stacksshows stack names - Dependencies: Reference stacks by name in
settings.depends_on - Terraform Workspaces: Workspace names derive from stack names
- Describe Commands:
atmos describe stacksuses stack names as keys
Best Practices
-
Prefer
name_templatefor new projects - Programmatic naming ensures consistency and reduces manual effort. -
Use
nameas an escape hatch - Reserve explicit names for migrations, legacy systems, or acquisitions. -
Document your naming convention - Whether using
name_templateor explicit names, document the pattern for your team. -
Consider Terraform state implications - Changing a stack's name changes its workspace, which affects state file location.
-
Keep names meaningful - Stack names should convey environment, region, and purpose at a glance.