Infraspec
Back to Blog
Arnab Chatterjee
Arnab Chatterjee

Atmos in Practice: A Stacks Repo, Versioned Component Repos and the Lifecycle Between Them

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 .tf files 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.tf and outputs.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:

  1. Reads the dev stack file and every file it imports.
  2. Merges them into one final set of variables for vpc.
  3. Writes the Terraform backend config and a variables file for you.
  4. Runs terraform init and terraform plan in the component's folder.

You get a normal Terraform plan. Atmos just did the wiring you'd otherwise do by hand.

Key terms

TermWhat it means
ComponentA piece of Terraform code you deploy, such as vpc or eks.
StackA YAML file describing one environment, such as dev.yaml. Its name is what you pass to -s.
ImportA stack can pull in other YAML files, so shared settings are written once.
Deep mergeAtmos combines imported files key by key. When two files set the same value, the one loaded later wins.
CatalogOur name for reusable YAML files holding a component's defaults. Stacks import them.
Source / vendoringAtmos 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            # generated

Conventions:

  • Terraform code lives in src/, so the source URI is github.com/acme/aws-<component>.git//src.
  • Every component takes the baseline variables project, aws_region, stage and tags. Values that are the same in every environment (project, aws_region and tags) are set once in globals.yaml. stage is different for each environment, so each environment sets it in its own <env>/_defaults.yaml.
  • Resource names are prefixed ${var.project}-${var.stage}, for example acme-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:

WorkflowTriggerWhat it does
terraform-validatePRfmt, validate, TFLint, Checkov, terraform test
release-previewPRDry-runs semantic-release and comments the next version
alpha-release/alpha-release PR commentCuts a pre-release tag from the PR branch
release-versionMerge to mainValidates, 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>.yaml

Atmos 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: true

The 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_subnets

There are two things to note here:

  • The version is pinned per environment. Dev can run v2.2.0-alpha.1 while prod stays on v2.1.0. Promoting a version means changing one line, one environment at a time.
  • !terraform.state reads 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: null

The 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 default

Atmos 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 catalog

A 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 catalogIn the environment stack
The source URIThe 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 defaultWiring to other components (!terraform.state vpc dev vpc_id)
Defaults suited to prodAccount-specific values, such as peer account IDs and RAM share principals

Our rules for catalog files

  • Declare every variable, even when the default is null or []. One file then lists every setting a component has. The IPAM catalog, for example, has ram_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 in dev.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 dev

This 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.

Atmos CI/CD workflow: a changed stack file is discovered, validated and planned on the pull request, then applied after review and merge

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:

  1. picks the GitHub OIDC role for that stage;
  2. runs atmos validate component;
  3. runs the plan;
  4. 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 missing

It'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 the infra-stacks repo.

Copy the role ARN it prints into the matching GitHub variable, and the environment is ready.

Part 5: The lifecycle

Adding a component

  1. Component repo: write src/ and open a PR. CI validates it and previews the version. Merging releases v1.0.0.
  2. Catalog: add stacks/catalog/<component>/defaults.yaml, with the source URI, schema link and every variable with its default.
  3. Schema: add stacks/schemas/jsonschema/<component>.json, checked against the component's variables.tf.
  4. Stack: import the catalog in dev.yaml and pin source.version.
  5. PR: the plan is posted. Merge, and it's applied.
  6. 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 two-repository release loop: an aws-eks pull request creates alpha releases for dev testing, then a stable release is pinned in dev, staging and prod

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:

  1. Turn off the safety switches in a PR. For example, set enable_deletion_protection: false in the stack. If the component has lifecycle { prevent_destroy = true }, cut a component release that relaxes it and pin that version. Apply.
  2. Destroy with atmos terraform destroy <component> -s <stage>, using an engineer's admin credentials.
  3. Clean up in a PR: remove the component from the stack file and, if no environment uses it any more, from the catalog.
  4. Recreating instead of removing (for example, renaming an EKS cluster)? Apply the new config, then turn prevent_destroy and 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-baseline component 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-exitcode across every stack would surface it within a day.
→

Need help applying this in production?

Talk directly with an engineer who works on these systems.

Talk to us