Skip to content

Commit 7619737

Browse files
ostermanclaude
andcommitted
docs: Add stack naming documentation and update Terragrunt migration guide
- Create website/docs/stacks/name.mdx documenting the `name` stack manifest field - Present choice between `name_template` (declarative) vs `name` (imperative) - Add "Stack Naming for Migrations" section to Terragrunt migration guide - Update stacks overview to include `name` in configuration sections table - Update learn/stacks/stacks.mdx with precedence order and links - Fix broken documentation links in blog post 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent d53cf4b commit 7619737

File tree

5 files changed

+273
-5
lines changed

5 files changed

+273
-5
lines changed

website/blog/2025-12-03-stack-manifest-name-override.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ This feature is analogous to `metadata.name` for components, which allows renami
134134

135135
## Related Documentation
136136

137-
- [Stack Configuration](/core-concepts/stacks)
138-
- [Stack Naming](/cli/configuration/stacks)
139-
- [Terraform Workspaces](/core-concepts/components/terraform/workspaces)
137+
- [Stack Names](/stacks/name)
138+
- [Stack Configuration](/stacks)
139+
- [Terraform Workspaces](/components/terraform/workspaces)
140140

141141
## Get Started
142142

website/docs/learn/stacks/stacks.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,14 @@ various [design patterns](/design-patterns/).
5252

5353
Every stack is uniquely identified by a name. The name is used to reference the stack in the Atmos CLI, or with stack dependencies.
5454

55-
These are computed from either the `name_pattern` (old way) or the more configurable
56-
`name_template` (new way). These are configured in the `atmos.yaml` configuration file.
55+
Stack names are determined using this precedence order:
56+
57+
1. **[`name`](/stacks/name)** field in the stack manifest (explicit override)
58+
2. **`name_template`** in `atmos.yaml` (Go template-based)
59+
3. **`name_pattern`** in `atmos.yaml` (token-based)
60+
4. **Default** - basename of the stack file
61+
62+
Use `name_template` when you have consistent context variables across all stacks. Use the [`name` field](/stacks/name) when migrating from other tools or when your infrastructure doesn't follow a strict naming convention.
5763

5864
For example, using the slug, we can reference a stack like this when applying the `vpc` stack in the `us2-dev` environment:
5965

website/docs/migration/terragrunt.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,54 @@ In Atmos terminology, root modules are called **components**. Each component is
889889
- [ ] Train team on new commands
890890
</TaskList>
891891

892+
## Stack Naming for Migrations
893+
894+
When migrating from Terragrunt, your existing Terraform state is tied to specific workspace names. Atmos needs to know the correct stack names to find this state. You have two options:
895+
896+
### Option 1: Use `name_template` (Recommended for Consistent Patterns)
897+
898+
If your Terragrunt setup used a consistent directory structure that maps to context variables, configure `name_template` in `atmos.yaml`:
899+
900+
<File title="atmos.yaml">
901+
```yaml
902+
stacks:
903+
name_template: "{{ .vars.environment }}-{{ .vars.stage }}"
904+
```
905+
</File>
906+
907+
This works well when:
908+
- Your Terragrunt directories followed a pattern like `prod/us-east-1/vpc/`
909+
- You can map that pattern to consistent `vars` in your stack manifests
910+
- All stacks use the same naming convention
911+
912+
### Option 2: Use Explicit `name` Field (For Inconsistent or Legacy Naming)
913+
914+
If your workspace names are ad-hoc or don't follow a consistent pattern, use the `name` field in each stack manifest:
915+
916+
<File title="stacks/us-east-1/prod/vpc.yaml">
917+
```yaml
918+
name: "prod-us-east-1-vpc" # Matches existing Terraform workspace exactly
919+
920+
import:
921+
- catalog/vpc
922+
923+
components:
924+
terraform:
925+
vpc:
926+
vars:
927+
cidr: "10.0.0.0/16"
928+
```
929+
</File>
930+
931+
This is the right choice when:
932+
- Workspace names don't follow a pattern you can express as a template
933+
- You're migrating infrastructure from multiple sources with different naming conventions
934+
- You need exact control over workspace names to match existing state
935+
936+
The `name` field takes precedence over `name_template`, so you can use both approaches—template for most stacks, explicit names for exceptions.
937+
938+
For complete documentation on stack naming, see [Stack Names](/stacks/name).
939+
892940
## Why Migrate?
893941

894942
### Advantages of Atmos

website/docs/stacks/name.mdx

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
---
2+
title: Stack Names
3+
sidebar_position: 2
4+
sidebar_label: name
5+
sidebar_class_name: command
6+
description: Use the name field to explicitly set a stack's logical name, or use name_template for programmatic naming.
7+
id: name
8+
---
9+
import File from '@site/src/components/File'
10+
import Intro from '@site/src/components/Intro'
11+
12+
<Intro>
13+
Every stack in Atmos has a logical name used for identification, the `-s` flag, dependencies, and Terraform workspaces.
14+
You can either set this name explicitly using the `name` field in your stack manifest, or compute it programmatically
15+
using `name_template` in `atmos.yaml`.
16+
</Intro>
17+
18+
## Choosing Your Approach
19+
20+
Atmos offers two approaches for stack naming. Choose based on your infrastructure's consistency:
21+
22+
| Approach | Where | When to Use |
23+
|----------|-------|-------------|
24+
| `name_template` | `atmos.yaml` | Consistent context variables across all stacks |
25+
| `name` | Stack manifest | Inconsistent naming, migrations, or legacy infrastructure |
26+
27+
### Use `name_template` When
28+
29+
You should use `name_template` in `atmos.yaml` when:
30+
31+
- You have consistent context variables (like `namespace`, `tenant`, `environment`, `stage`) across all stacks
32+
- All your root modules use these variables deterministically
33+
- You want programmatic, convention-based naming (e.g., following the [null-label](https://github.com/cloudposse/terraform-null-label) pattern)
34+
35+
<File title="atmos.yaml">
36+
```yaml
37+
stacks:
38+
name_template: "{{ .vars.tenant }}-{{ .vars.environment }}-{{ .vars.stage }}"
39+
```
40+
</File>
41+
42+
With this configuration, a stack with `vars.tenant: acme`, `vars.environment: ue1`, and `vars.stage: prod` will automatically be named `acme-ue1-prod`.
43+
44+
### Use `name` When
45+
46+
You should use the `name` field in your stack manifest when:
47+
48+
- You're migrating from Terragrunt or another tool and need to preserve existing workspace names
49+
- Your infrastructure has inconsistent naming that doesn't follow a pattern
50+
- You have legacy stacks that predate your naming conventions
51+
- You need to match existing Terraform workspace names exactly
52+
- Any inconsistency in your vars would break a deterministic template
53+
54+
<File title="stacks/legacy-prod.yaml">
55+
```yaml
56+
name: "my-legacy-prod-stack"
57+
58+
import:
59+
- catalog/defaults
60+
61+
components:
62+
terraform:
63+
vpc:
64+
vars:
65+
cidr: "10.0.0.0/16"
66+
```
67+
</File>
68+
69+
With this configuration, the stack is identified as `my-legacy-prod-stack` regardless of the filename or any `name_template` in `atmos.yaml`.
70+
71+
## Precedence Order
72+
73+
When determining a stack's name, Atmos uses this precedence order:
74+
75+
1. **`name`** (highest) - Explicit name from stack manifest
76+
2. **`name_template`** - Go template from `atmos.yaml`
77+
3. **`name_pattern`** - Token-based pattern from `atmos.yaml`
78+
4. **Default** - Basename of the stack file (e.g., `prod.yaml` → `prod`)
79+
80+
This means the `name` field always wins, allowing you to override programmatic naming for specific stacks.
81+
82+
## Configuration
83+
84+
The `name` field is a top-level key in stack manifests, at the same level as `import`, `vars`, and `components`:
85+
86+
```yaml
87+
name: "explicit-stack-name"
88+
89+
import:
90+
- catalog/base
91+
92+
vars:
93+
environment: prod
94+
95+
components:
96+
terraform:
97+
vpc:
98+
vars:
99+
cidr: "10.0.0.0/16"
100+
```
101+
102+
## Examples
103+
104+
### Migrating from Terragrunt
105+
106+
When migrating from Terragrunt, your existing Terraform state is tied to specific workspace names. Use `name` to preserve these:
107+
108+
<File title="stacks/us-east-1/prod/vpc.yaml">
109+
```yaml
110+
name: "prod-us-east-1-vpc" # Matches existing Terraform workspace
111+
112+
import:
113+
- catalog/vpc
114+
115+
components:
116+
terraform:
117+
vpc:
118+
vars:
119+
cidr: "10.0.0.0/16"
120+
```
121+
</File>
122+
123+
This ensures `atmos terraform apply vpc -s prod-us-east-1-vpc` uses the existing state without requiring state migrations.
124+
125+
### Legacy Infrastructure
126+
127+
For infrastructure that predates your naming standards:
128+
129+
<File title="stacks/old-datacenter.yaml">
130+
```yaml
131+
name: "dc1-legacy-infra" # Historical name that must be preserved
132+
133+
components:
134+
terraform:
135+
network:
136+
vars:
137+
vpc_id: "vpc-abc123"
138+
```
139+
</File>
140+
141+
### Mixed Approach
142+
143+
You can use `name_template` for most stacks while overriding specific ones with `name`:
144+
145+
<File title="atmos.yaml">
146+
```yaml
147+
stacks:
148+
name_template: "{{ .vars.tenant }}-{{ .vars.environment }}-{{ .vars.stage }}"
149+
```
150+
</File>
151+
152+
<File title="stacks/acme/prod/us-east-1.yaml">
153+
```yaml
154+
# Uses name_template: acme-prod-ue1
155+
vars:
156+
tenant: acme
157+
environment: prod
158+
stage: ue1
159+
160+
components:
161+
terraform:
162+
vpc:
163+
vars:
164+
cidr: "10.0.0.0/16"
165+
```
166+
</File>
167+
168+
<File title="stacks/legacy-acquisition.yaml">
169+
```yaml
170+
name: "acquired-company-prod" # Overrides name_template for this stack
171+
172+
vars:
173+
tenant: acquired
174+
environment: prod
175+
stage: main
176+
177+
components:
178+
terraform:
179+
vpc:
180+
vars:
181+
cidr: "10.1.0.0/16"
182+
```
183+
</File>
184+
185+
## How Stack Names Are Used
186+
187+
Stack names appear throughout Atmos:
188+
189+
- **CLI**: `atmos terraform apply vpc -s my-stack-name`
190+
- **Listing**: `atmos list stacks` shows stack names
191+
- **Dependencies**: Reference stacks by name in `settings.depends_on`
192+
- **Terraform Workspaces**: Workspace names derive from stack names
193+
- **Describe Commands**: `atmos describe stacks` uses stack names as keys
194+
195+
## Best Practices
196+
197+
1. **Prefer `name_template` for new projects** - Programmatic naming ensures consistency and reduces manual effort.
198+
199+
2. **Use `name` as an escape hatch** - Reserve explicit names for migrations, legacy systems, or acquisitions.
200+
201+
3. **Document your naming convention** - Whether using `name_template` or explicit names, document the pattern for your team.
202+
203+
4. **Consider Terraform state implications** - Changing a stack's name changes its workspace, which affects state file location.
204+
205+
5. **Keep names meaningful** - Stack names should convey environment, region, and purpose at a glance.
206+
207+
## Related
208+
209+
- [Stack Configuration](/stacks)
210+
- [Imports](/stacks/imports)
211+
- [Variables (vars)](/stacks/vars)
212+
- [Terraform Workspaces](/components/terraform/workspaces)
213+
- [Migrating from Terragrunt](/migration/terragrunt)

website/docs/stacks/stacks.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Stack manifests support various configuration sections at different scopes:
2020

2121
| Section | Description | Scopes |
2222
|---------|-------------|--------|
23+
| [name](/stacks/name) | Explicit stack name override | Stack manifest only |
2324
| [vars](/stacks/vars) | Variables passed to components | Global, component-type, component |
2425
| [env](/stacks/env) | Environment variables | Global, component-type, component |
2526
| [settings](/stacks/settings) | Integrations and metadata | Global, component-type, component |

0 commit comments

Comments
 (0)