Manage Lifecycle Events with Hooks
Atmos hooks run automated actions around Terraform, Kubernetes, Helm, and Helmfile component
operations. Built-in kinds cover cost analysis, security scanning, stores, Git, and CI; kind: step
and kind: steps make the complete typed step library available at lifecycle events.
Browse the shared Steps reference and step type catalog for the building blocks available in workflows, custom commands, and lifecycle hooks.
For a complete synthesis example, see Deploy AWS CDK and CDK Terrain with Hooks.
Hooks Schema
Each hook has a kind that selects an engine and a set of defaults. The
generic command kind runs any binary; named kinds like infracost,
trivy, and tflint ship sane defaults so you don't need to write any wiring.
components:
terraform:
vpc:
hooks:
# Cost diff after every plan — zero config.
cost:
events: [after.terraform.plan]
kind: infracost
# Security scan after every plan.
security:
events: [after.terraform.plan]
kind: trivy
# Store outputs after apply (the original hook use case).
outputs:
events: [after.terraform.apply]
kind: store
name: prod/ssm
outputs:
vpc_id: .id
Hooks can be declared at the global level, the terraform section, an
individual component, or in the overrides section. Partial config at
each level merges into the final result so you can keep configuration
DRY.
Supported Lifecycle Events
| Family | Events |
|---|---|
| Terraform | before/after.terraform.init, plan, apply, destroy, test, output, and refresh; deploy normalizes to apply. Aggregate events fire once for multi-component runs: before/after.terraform.plan.aggregate, before/after.terraform.apply.aggregate, and before/after.terraform.destroy.aggregate. |
| Kubernetes | before/after.kubernetes.render, diff/plan, apply/deploy, delete, and validate. plan normalizes to diff; deploy normalizes to apply. |
| Native Helm | before/after.helm.template, diff, apply/deploy, and delete. deploy normalizes to apply. CI aggregate events include after.helm.plan.aggregate and after.helm.apply.aggregate. |
| Helmfile | before/after.helmfile.template, diff, apply/sync/deploy, destroy, and version. sync and deploy normalize to apply. |
| CloudFormation | before/after.aws/cloudformation.diff, apply, delete, drift-detect, drift-describe, changeset-create, and changeset-execute. The aliases plan and deploy use the diff and apply events; the changeset events are separate and are not aliases of apply. See CloudFormation lifecycle hooks. |
| Documentation generation | before.docs.generate and after.docs.generate. These are declared under docs.generate.<type>.hooks in atmos.yaml, not stack manifests, and support kind: step, kind: steps, and kind: command. They have no component or stack. See atmos docs generate. |
| Scaffold generation | before.scaffold.generate and after.scaffold.generate. These are declared in scaffold.yaml, not stack manifests, and support only kind: step and kind: steps. |
Hooks with no events list fire on every supported event for backward
compatibility with configs written before event filtering existed. You
should use the dotted form (after.terraform.plan) in new configs. The
legacy hyphenated form (after-terraform-plan) is still accepted and
equivalent for backward compatibility.
The before.terraform.init and after.terraform.init events fire around the
explicit atmos terraform init command. They do not fire for the implicit
init that plan, apply, and deploy run automatically — use
before.terraform.plan / before.terraform.apply for those.
For init and destroy, before-hooks run after authentication, source and
workdir provisioning, and configuration generation, before Terraform runs
(including any implicit init). For test, before-hooks run after source and
workdir provisioning but before authentication and Terraform configuration
generation, so they can start fixtures such as an emulator needed by the
component's identity. Hook commands and steps use the prepared component workdir
by default. After-hooks run when the operation finishes, with its success or
failure outcome. In multi-component runs, these events fire separately for each
component; they are not aggregate events.
The atmos stack deploy and atmos stack destroy commands run each component's own
command, so the per-component events fire as usual. For example, stack deploy on a
Helmfile component runs helmfile apply and fires before.helmfile.apply and
after.helmfile.apply. Running either command with --dry-run previews the hooks that
would fire without running them. See atmos stack deploy
and atmos stack destroy.
Event validation and editions
Hook event names must be registered lifecycle events. A typo such as
after.terraform.aply is an error, even if when would be false or
--skip-hooks would skip the hook. Validation runs during stack processing,
including atmos validate stacks and stack previews, and before scaffold
hooks or file writes, including scaffold dry runs.
This behavior applies to unpinned projects and editions
on or after 2026-10-19. To retain the earlier behavior while correcting
existing declarations, pin an earlier date in atmos.yaml:
edition: "2026-10-18"
Earlier editions accept arbitrary event names and skip unmatched events with
debug logging. Partial pins round to the end of the period: "2026-10" and
"2026" enable validation. The transition is listed as
hooks.registered_events in edition inspection; it is not a YAML setting.
Use the event names in the table above. For example, atmos helm destroy is a
command alias for delete, so its hook events are before.helm.delete and
after.helm.delete. Helmfile uses before.helmfile.destroy and
after.helmfile.destroy. Naming a custom command does not register new hook
events. Registered events that do not match the current operation are still
skipped, and empty event lists retain their match-all behavior.
Event names are matched as written. Hook discovery does not render templates, so
an expression such as {{ .vars.hook_event }} in events could never match a
lifecycle event; it is rejected like any other unregistered name. Declare each
event name literally.
Supported Kinds
Stack hooks support command, store, git, infracost, trivy, checkov, kics, step,
and steps.
The named kinds below provide purpose-built defaults; kind: command is the general binary
runner. Scaffold hooks reuse the when: vocabulary and step engine but reject every kind except
step and steps because they do not have stack/component execution context.
Scaffold hooks receive the same ATMOS_HOOK_STATUS, ATMOS_HOOK_EXIT_CODE, and
ATMOS_HOOK_ERROR outcome variables as stack hooks; see
Reacting to success or failure.
The legacy ci.check, ci.output, ci.summary, ci.upload, and ci.download kinds still parse
for compatibility but are deprecated no-ops. Use current CI provider bindings rather than adding
new ci.* hook configuration.