Skip to main content

Manage Lifecycle Events with Hooks

Atmos supports the ability to take action at various points in the lifecycle of your components. This is done by configuring the hooks section in your stack manifest for the component that you want to take action on.

Hooks Schema

The hooks section schema is as follows:

hooks:
store-outputs:
events:
- after-terraform-apply
command: store
name: prod/ssm
outputs:
vpc_id: .id

This schema can be specified at the top level of the stack configuration (global), within the terraform section, inside individual components, or in the overrides section. Partial config can also be specified at various levels to help keep the configuration DRY.

An example demonstrating this concept is below:

At the global level, set that the store command will run after terraform apply:

# stacks/catalog/vpc/_defaults.yaml (global)
hooks:
store-outputs:
events:
- after-terraform-apply
command: store

In the production account, use the prod/ssm store (configured in atmos.yaml):

# stacks/orgs/acme/plat/prod/_defaults.yaml (terraform)
terraform:
hooks:
store-outputs:
name: prod/ssm

At the component level, specify that the id output of the component should be stored in the store as the vpc_id key:

# stacks/orgs/acme/plat/prod/us-east-2.yaml (component)
components:
terraform:
vpc:
hooks:
store-outputs:
outputs:
vpc_id: .id

Supported Lifecycle Events

Atmos supports the following lifecycle events:

  • after-terraform-apply (this event is triggered after the atmos terraform apply or atmos terraform deploy command is run)

Supported Commands

store

The store command is used to write data to a remote store.

hooks.[hook_name]
This map key is the name you want to give to the hook. This must be unique for each hook in the component.
hooks.[hook_name].events

This is a list of Supported Lifecycle Events that should trigger running the command.

hooks.[hook_name].command
Must be set to store
hooks.[hook_name].name
The name of the store to use.
hooks.[hook_name].outputs

A map of values that will be written to the store under the key for this component. The key is the name of the key in the store. The value is the value to write to the store. If the value begins with a dot (.), it will be treated as a Terraform output and the value will be retrieved from the Terraform state for the current component.