Skip to main content

Configure Terraform

Atmos natively supports opinionated workflows for Terraform and OpenTofu. It's compatible with every version of terraform and designed to work with multiple different versions of Terraform concurrently.

Keep in mind that Atmos does not handle the downloading or installation of Terraform; it assumes that any required commands are already installed on your system. To automate this, consider creating a Custom Command to install Terraform.

Atmos provides many settings that are specific to Terraform and OpenTofu.

CLI Configuration

All of these settings are defined by default in the Atmos CLI Configuration found in atmos.yaml, but can also be overridden at any level of the Stack configuration.

components:
terraform:
# The executable to be called by `atmos` when running Terraform commands
command: "/usr/bin/terraform-1"
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_BASE_PATH' ENV var, or '--terraform-dir' command-line argument
# Supports both absolute and relative paths
base_path: "components/terraform"
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_APPLY_AUTO_APPROVE' ENV var
apply_auto_approve: false
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_DEPLOY_RUN_INIT' ENV var, or '--deploy-run-init' command-line argument
deploy_run_init: true
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_INIT_RUN_RECONFIGURE' ENV var, or '--init-run-reconfigure' command-line argument
init_run_reconfigure: true
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_AUTO_GENERATE_BACKEND_FILE' ENV var, or '--auto-generate-backend-file' command-line argument
auto_generate_backend_file: false
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT' ENV var, or '--append-user-agent' command-line argument
append_user_agent: "Acme/1.0 (Build 1234; arm64)"
components.terraform.apply_auto_approve
if set to true, Atmos automatically adds the -auto-approve option to instruct Terraform to apply the plan without asking for confirmation when executing terraform apply command
components.terraform.deploy_run_init
if set to true, Atmos runs terraform init before executing atmos terraform deploy command
components.terraform.init_run_reconfigure
if set to true, Atmos automatically adds the -reconfigure option to update the backend configuration when executing terraform init command
components.terraform.auto_generate_backend_file
if set to true, Atmos automatically generates the Terraform backend file from the component configuration when executing terraform plan and terraform apply commands

Configuration

The settings for terraform can be defined in multiple places and support inheritance. This ensures that projects can override the behavior.

The defaults for everything are defined in the atmos.yaml.

components:
terraform:
...

The same settings, can be overridden by Stack configurations at any level:

  • terraform
  • components.terraform
  • components.terraform._component_

For example, we can change the terraform command used by a component (useful for legacy components)

components:
terraform:
vpc:
command: "/usr/local/bin/terraform-0.13"

Terraform Provider

A Terraform provider (cloudposse/terraform-provider-utils) implements a data source that can read the YAML Stack configurations natively from within terraform.

Terraform Module

A Terraform module (cloudposse/terraform-yaml-stack-config) wraps the data source.

Here's an example of accessing the variables for a given component from within a Terraform module.

module "vars" {
source = "cloudposse/stack-config/yaml//modules/vars"
# version = "x.x.x"

stack_config_local_path = "./stacks"
stack = "my-stack"
component_type = "terraform"
component = "my-vpc"

context = module.this.context
}