Running Terraform for one environment is simple. Running it for dev, staging and prod, with shared settings and safe upgrades, is where it gets messy. This post shows how we handle that with Atmos: how we lay out a multi-environment AWS setup, how Terraform components get versioned and released, and how a component is added, changed and removed day to day.
What is Atmos?
Atmos is an open-source Terraform orchestration tool from Cloud Posse. It doesn't replace Terraform. It manages the config for many environments and runs Terraform for you.
The problem it solves
Plain Terraform works well for one environment. With dev, staging and prod, teams usually end up with one of these:
- Copied folders such as
envs/dev/,envs/prod/, each with near-identical.tffiles that drift apart over time. - Lots of `.tfvars` files and backend blocks that have to be passed by hand with the right flags for each environment.
Both make it hard to answer simple questions, such as "how is prod different from dev?".
The core idea: separate code from config
Atmos splits your infrastructure into two kinds of files:
- Components are the Terraform code. A VPC component, for example, is a normal Terraform root module with
main.tf,variables.tfandoutputs.tf. You write it once. - Stacks are YAML files. A stack says which components to deploy in an environment and which values to give them.
The Terraform code never changes between environments. Only the YAML does.
What happens when you run Atmos
Take atmos terraform plan vpc -s dev. It means "plan the vpc component in the dev stack". Atmos then:
- Reads the
devstack file and every file it imports. - Merges them into one final set of variables for
vpc. - Writes the Terraform backend config and a variables file for you.
- Runs
terraform initandterraform planin the component's folder.
You get a normal Terraform plan. Atmos just did the wiring you'd otherwise do by hand.
Key terms
| Term | What it means |
|---|---|
| Component | A piece of Terraform code you deploy, such as vpc or eks. |
| Stack | A YAML file describing one environment, such as dev.yaml. Its name is what you pass to -s. |
| Import | A stack can pull in other YAML files, so shared settings are written once. |
| Deep merge | Atmos combines imported files key by key. When two files set the same value, the one loaded later wins. |
| Catalog | Our name for reusable YAML files holding a component's defaults. Stacks import them. |
| Source / vendoring | Atmos can download a component's code from a Git repo at a pinned version, so the code doesn't have to live in the stacks repo. |
Two commands are worth knowing early:
atmos describe component <component> -s <stack>shows the final merged config, before anything runs.atmos validate component <component> -s <stack>checks that config against a schema.
The rest of this post shows how we use these pieces in a real setup.
Our setup at a glance
The setup has two halves:
- Component repos, one per Terraform component (
aws-vpc,aws-eks,aws-iam,aws-ipam…). Each is independently versioned. - A stacks repo (
infra-stacks). It decides which version of which component goes where, with what config.
Part 1: The component repos
Every component lives in its own repository:
aws-<component>/
├── src/ # main.tf, variables.tf, outputs.tf,
│ └── versions.tf
├── .github/workflows/ # thin callers of org-level reusable workflows
├── .releaserc.json # semantic-release config
├── .tflint.hcl
├── .checkov.yml
├── .terraform-docs.yml
└── CHANGELOG.md # generatedConventions:
- Terraform code lives in
src/, so the source URI isgithub.com/acme/aws-<component>.git//src. - Every component takes the baseline variables
project,aws_region,stageandtags. Values that are the same in every environment (project,aws_regionandtags) are set once inglobals.yaml.stageis different for each environment, so each environment sets it in its own<env>/_defaults.yaml. - Resource names are prefixed
${var.project}-${var.stage}, for exampleacme-dev-….
Why a repo per component?
We wrote an ADR for this, and considered a components monorepo. Separate repos won on:
- Standard semver tags (
v1.2.0) instead of scoped tags (vpc/v1.2.0), which most tools don't understand. - Faster CI that only tests the component that changed.
- Smaller blast radius. A broken test in one component doesn't block the rest.
- Per-repo permissions instead of relying on CODEOWNERS.
It costs more to manage. The ADR records when we'd reverse it: tightly coupled components that need atomic cross-component changes, or a team of one or two people.
Releases are automated
All component repos call the same reusable workflows from the org's .github repo:
| Workflow | Trigger | What it does |
|---|---|---|
| terraform-validate | PR | fmt, validate, TFLint, Checkov, terraform test |
| release-preview | PR | Dry-runs semantic-release and comments the next version |
| alpha-release | /alpha-release PR comment | Cuts a pre-release tag from the PR branch |
| release-version | Merge to main | Validates, tags, publishes a GitHub release and updates the CHANGELOG |
A feat: PR title produces a minor bump. A fix: produces a patch bump. Nobody tags releases by hand.
/alpha-release is the important one. It lets you deploy an unmerged component change to dev through the stacks repo before you merge it. Say a component is on v1.0.0 and you open a feat: PR. Comment /alpha-release to get a pre-release tag for the next version, v1.1.0-alpha.1, and pin dev to it. Comment again after more pushes to get alpha.2. When the PR merges, the stable v1.1.0 is cut.
Part 2: The stacks repo
infra-stacks/
├── atmos.yaml
├── vendor.yaml
├── components/terraform/ # pulled at plan time, gitignored
├── stacks/
│ ├── globals.yaml # project, region, common tags
│ ├── catalog/
│ │ ├── vpc/defaults.yaml
│ │ ├── eks/defaults.yaml
│ │ └── iam/defaults.yaml
│ ├── shared/
│ │ ├── _defaults.yaml # backend for the shared account
│ │ └── shared.yaml
│ ├── dev/
│ │ ├── _defaults.yaml
│ │ └── dev.yaml
│ ├── staging/
│ └── prod/
├── stacks/schemas/jsonschema/ # one schema per component
├── scripts/bootstrap.sh
└── .github/workflows/One stack per environment
atmos.yaml keeps it simple:
stacks:
base_path: "stacks"
included_paths: ["**/*.yaml"]
excluded_paths: ["catalog/**", "**/_defaults.yaml"]
name_pattern: "{stage}"The stack name is just the stage: shared, dev, staging or prod. You target one component at a time with atmos terraform plan vpc -s dev.
shared is the core account. It holds things every environment uses, such as IPAM pools shared over RAM and Identity Center assignments. It's a stage of its own, so moving workloads to dedicated accounts later doesn't mean restructuring the repo.
Four layers of config
globals.yaml → <env>/_defaults.yaml →
catalog/<component>/defaults.yaml → <env>.yamlAtmos deep-merges these, and later layers win.
globals.yaml sets the project, region and tags:
vars:
project: acme
aws_region: ap-south-1
tags:
ManagedBy: Terraform
Repository: infra-stacks<env>/_defaults.yaml sets the stage and the backend. Each environment has its own state bucket:
import: [../globals]
vars:
stage: dev
state_bucket: acme-infra-stacks-tfstate-dev
terraform:
backend_type: s3
backend:
s3:
bucket: "{{ .vars.state_bucket }}"
region: "{{ .vars.aws_region }}"
encrypt: true
use_lockfile: true # S3 native locking, no DynamoDB table{{ .vars.state_bucket }} is a Go template. Atmos fills it in with the value of state_bucket from the same file. Go templates are on by default in recent Atmos versions. On older versions, turn them on in atmos.yaml:
templates:
settings:
enabled: trueThe catalog says what a component is: its source, its validation schema and its defaults. It's the core of the setup, so it gets its own section below.
The environment stack pins versions and overrides only what differs:
import:
- ./_defaults
- catalog/vpc/defaults
- catalog/eks/defaults
vars:
stage: dev # repeated so CI can read it without resolving imports
components:
terraform:
vpc:
source:
version: v2.2.0
vars:
single_nat_gateway: true # cheaper in dev
flow_log_expiration_days: 14
eks:
source:
version: v1.0.1
vars:
vpc_id: !terraform.state vpc dev vpc_id
subnet_ids: !terraform.state vpc dev private_app_subnetsThere are two things to note here:
- The version is pinned per environment. Dev can run
v2.2.0-alpha.1while prod stays onv2.1.0. Promoting a version means changing one line, one environment at a time. !terraform.statereads another component's outputs straight from its state. EKS doesn't need a hand-copied VPC ID.
The catalog pattern
Each component has exactly one catalog file:
stacks/catalog/<component>/defaults.yaml. That file describes the component and its default behavior. An environment imports it and changes only what has to differ.
# stacks/catalog/vpc/defaults.yaml
components:
terraform:
vpc:
settings:
validation:
validate-vpc:
schema_type: jsonschema
schema_path: "vpc.json"
source:
uri: github.com/acme/aws-vpc.git//src
# version is set per environment stack file
vars:
name: main
vpc_netmask_length: 19
availability_zones: [ap-south-1a, ap-south-1b, ap-south-1c]
enable_nat_gateway: true
single_nat_gateway: false
enable_flow_logs: true
flow_log_expiration_days: 90
enable_interface_endpoints: false
peer_account_id: null
alarm_sns_topic_arn: nullThe dev stack imports that file and overrides just two values:
# stacks/dev/dev.yaml
import:
- ./_defaults
- catalog/vpc/defaults
vars:
stage: dev # repeated so CI can read it without resolving imports
components:
terraform:
vpc:
source:
version: v2.2.0
vars:
single_nat_gateway: true # one NAT gateway is enough for dev
flow_log_expiration_days: 14 # shorter retention than the 90-day defaultAtmos merges the two. The VPC that dev actually gets looks like this:
# atmos describe component vpc -s dev (vars, trimmed)
vars:
project: acme # from globals.yaml
aws_region: ap-south-1 # from globals.yaml
stage: dev # from dev/_defaults.yaml, repeated in dev.yaml
name: main # from the catalog
vpc_netmask_length: 19 # from the catalog
availability_zones: [ap-south-1a, ap-south-1b, ap-south-1c] # from the catalog
enable_nat_gateway: true # from the catalog
single_nat_gateway: true # overridden in dev.yaml
enable_flow_logs: true # from the catalog
flow_log_expiration_days: 14 # overridden in dev.yaml
enable_interface_endpoints: false # from the catalogA prod stack that imports the same catalog with no vars overrides would get one NAT gateway per AZ and 90-day flow logs.
What goes where
| In the catalog | In the environment stack |
|---|---|
| The source URI | The version pin |
| The validation hook (the component's JSON schema) | Values that differ per environment, such as NAT gateways, log retention and budgets |
| Every variable, with a default | Wiring to other components (!terraform.state vpc dev vpc_id) |
| Defaults suited to prod | Account-specific values, such as peer account IDs and RAM share principals |
Our rules for catalog files
- Declare every variable, even when the default is
nullor[]. One file then lists every setting a component has. The IPAM catalog, for example, hasram_share_principals: []with the comment "set per environment". Reviewers can see an empty value is intentional, not forgotten. - Default to what prod needs. The VPC catalog uses one NAT gateway per AZ and 90-day flow logs, and dev opts down. If someone forgets an override, the environment ends up safe but more expensive, rather than cheap but fragile.
- Never put a version in the catalog. A version there would upgrade every environment that doesn't override it, all at once. Pins live in the stack files, so every upgrade is a visible, per-environment diff.
- No per-environment catalog files. We don't create files like
catalog/vpc/dev.yaml. Overrides go directly indev.yaml, so each environment's differences sit in one file instead of being spread across layers. - Keep the schema in step. When a component gains a variable, the same PR adds it to the catalog and to the JSON schema, checked against the component's
variables.tf.
See the merged result before you trust it:
atmos describe component vpc -s devThis prints the final vars after globals, _defaults, the catalog and the stack are merged. It's the quickest way to answer "where is this value coming from?".
Catalog changes are rolled out by hand, on purpose. A catalog file is imported by every environment. If CI applied it on merge, one PR would change dev, staging and prod at the same moment. So the PR workflow deliberately ignores catalog/** (see Part 3). After a catalog change merges, we run the manual workflow for dev first, check it, then staging, then prod.
The trade-off: until an environment has been rolled out, its next stack PR will also show the pending catalog change in its plan. Roll catalog changes out promptly, so they don't turn up in someone else's review.
Validation before Terraform runs
Every component has a JSON schema in stacks/schemas/jsonschema/, and the catalog wires it in. atmos validate component eks -s dev catches a misspelled variable or wrong type before a plan is even attempted. CI runs it before every plan and every apply.
Our rule: when a component gains a variable, the PR that adds it to the catalog also adds it to the schema.
Part 3: CI/CD
All of it lives in one workflow, terraform-deployment.yaml. It triggers on changes to stacks/**/*.yaml.

Discover. The workflow finds which stack files changed, ignoring globals.yaml, catalog/** and _defaults.yaml. A small script then turns each changed file into {stage, component} pairs. It reads .vars.stage and the keys under components.terraform straight from the file, without resolving imports. That's why each stack file repeats stage, even though _defaults.yaml already sets it. If a PR touches more than one environment, it gets a warning suggesting you split it.
Plan (on PR). For each pair, the job:
- picks the GitHub OIDC role for that stage;
- runs
atmos validate component; - runs the plan;
- posts the result as a PR comment. Each component gets its own comment, which is updated on re-runs. Plans with no changes get a ✅ instead of a wall of text.
Apply (on merge to `main`). The same matrix runs atmos terraform apply -auto-approve. It runs one component at a time (max-parallel: 1) under a repo-wide concurrency group, so two merges never apply at once.
Manual workflow. A workflow_dispatch workflow plans or applies every component in a chosen environment. It's useful after a catalog or _defaults change, which the PR workflow ignores on purpose. It's bound to a GitHub Environment, so you can add required reviewers for prod.
Auth. Each stage has its own role ARN stored as a GitHub variable (DEV_GH_ROLE, PROD_GH_ROLE…). There are no long-lived keys anywhere.
Part 4: Bootstrap
CI needs a state bucket and a role before it can run, so scripts/bootstrap.sh creates them. Run it once per environment with admin credentials:
./scripts/bootstrap.sh dev --info # show what exists, change nothing
./scripts/bootstrap.sh dev # create whatever is missingIt's idempotent and creates three things:
- The state bucket
acme-infra-stacks-tfstate-<env>, with versioning, encryption, a public access block and old-version expiry. - The GitHub OIDC provider for the account.
- The deploy role
github-actions-infra-stacks-<env>, trusted by theinfra-stacksrepo.
Copy the role ARN it prints into the matching GitHub variable, and the environment is ready.
Part 5: The lifecycle
Adding a component
- Component repo: write
src/and open a PR. CI validates it and previews the version. Merging releasesv1.0.0. - Catalog: add
stacks/catalog/<component>/defaults.yaml, with the source URI, schema link and every variable with its default. - Schema: add
stacks/schemas/jsonschema/<component>.json, checked against the component'svariables.tf. - Stack: import the catalog in
dev.yamland pinsource.version. - PR: the plan is posted. Merge, and it's applied.
- Promote: repeat step 4 for staging and prod in their own PRs.
Changing a component
If only config changes, edit the vars in the environment stack. You get a PR, a plan and an apply on merge.
If the code changes, it's a two-repo loop:

The alpha tag is what makes this work. You test against real infrastructure in dev without merging half-finished code into the component's main.
Removing a component
Removal is the step our pipeline does least for, and that's on purpose.
The CI matrix is built from the components that are in the changed stack file. So deleting a component's block from YAML doesn't destroy anything. The component simply drops out of CI, and its resources and state stay where they are. That makes accidental deletes hard. It also means removing something is a deliberate, hands-on job:
- Turn off the safety switches in a PR. For example, set
enable_deletion_protection: falsein the stack. If the component haslifecycle { prevent_destroy = true }, cut a component release that relaxes it and pin that version. Apply. - Destroy with
atmos terraform destroy <component> -s <stage>, using an engineer's admin credentials. - Clean up in a PR: remove the component from the stack file and, if no environment uses it any more, from the catalog.
- Recreating instead of removing (for example, renaming an EKS cluster)? Apply the new config, then turn
prevent_destroyand deletion protection back on in a follow-up release.
What's worked, and what we'd change
Worked well:
- The catalog / stack split. New environments are a short YAML file. Reviews show only what differs.
- Per-environment version pins plus alpha releases. Upgrades get tested in dev, and promotion is a one-line diff.
- Validating against the schema before every plan. Typos fail in seconds, not halfway through an apply.
- Delete-by-removal doesn't destroy. Removing a component from a stack file can't take down infrastructure by mistake.
On the list:
- Bootstrap is outside Terraform. The bucket and roles the script creates aren't in state. Importing them into an
account-baselinecomponent would put them under review like everything else. - Drift only shows up when a component is next planned. A plan does reveal console changes, but only for the components a PR touches. A component nobody edits for months can drift unnoticed. A scheduled
plan -detailed-exitcodeacross every stack would surface it within a day.

