# Deploy Everything

After you've written your components and configured your stacks, now we're ready to deploy them!

> **Key points**
>
> - How Atmos identifies components using context variables and naming patterns
> - How to preview your configurations and changes before applying them
> - How to deploy every Terraform component in a selected stack

## Deploy the Stack

Before deploying, validate the stack manifests:

```shell
atmos validate stacks
```

You can also orient yourself with the built-in list commands:

```shell
atmos list stacks
atmos list instances -s dev
```

Preview every Terraform component in the `dev` stack:

```shell
atmos terraform plan --all -s dev
```

Deploy every Terraform component in the `dev` stack:

```shell
atmos terraform deploy --all -s dev
```

When you're done, you can destroy every Terraform component in the stack:

```shell
atmos terraform destroy --all -s dev -auto-approve
```

:::tip Let Atmos prompt you
For single-component Terraform commands, you can name the component explicitly or omit the component and stack in an interactive terminal so Atmos can prompt you:

```shell
# Explicit
atmos terraform plan station -s dev

# Interactive: choose component, then stack
atmos terraform plan
```

For bulk operations, use explicit selectors such as `--all`, `--components`, or `--query`.
:::

## Stack Search Algorithm

Looking at the commands above, you might have a question "How does Atmos find the component in the stack and all the variables?"

Let's consider what Atmos does when executing the command `atmos terraform deploy --all -s dev`:

- Atmos uses the `stacks.name_template` defined in the [CLI config](/quick-start/advanced/configure-project). In this example, we have defined a simple name based on `stacks.name_template: "{{ .vars.stage }}"`. This means that the stack name is just the `stage` part of the stack name.

- Atmos searches for the stack configuration file (in the `stacks` folder and all sub-folders) where `stage: dev` is defined (inline or via imports). During the search, Atmos processes all parent (top-level) config files and compares the context variables specified in the command (`-s` flag) with the context variables defined in the stack configurations, finally finding the matching stack

- Atmos finds every Terraform component in the stack. In this simple Quick Start, that means Atmos resolves the `station` component by processing all the inline configs and all the imports

- Atmos deep-merges all the catalog imports for the `station` component and then deep-merges all the variables for the component defined in all sections (global `vars`, terraform `vars`, base components `vars`, component `vars`), producing the final variables for the `station` component in the `dev` stack

- And lastly, Atmos writes the final deep-merged variables into a `.tfvar.json` file in the component directory and then
  executes the Terraform command

**Ready to take the next step?**

Now that you’ve seen Atmos in action, you can explore the extra credit!

Or take a moment to explore its core concepts. You have only just scratched the surface of Atmos. Atmos is a powerful enterprise-grade framework with so **much more to offer**!

Extra Credit[Read more](/quick-start/simple/extra-credit)
Deep Dive
