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)"
plan:
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_PLAN_SKIP_PLANFILE' ENV var, or '--skip-planfile' command-line argument
skip_planfile: false
components.terraform.command- The executable to be called by Atmos when running Terraform commands
components.terraform.base_path- The root directory where the Terraform components and configurations are located. This path serves as the starting point for resolving any relative paths within the Terraform setup.
components.terraform.apply_auto_approve- if set to
true, Atmos automatically adds the-auto-approveoption to instruct Terraform to apply the plan without asking for confirmation when executingterraform applycommand components.terraform.deploy_run_init- if set to
true, Atmos runsterraform initbefore executingatmos terraform deploycommand components.terraform.init_run_reconfigure- if set to
true, Atmos automatically adds the-reconfigureoption to update the backend configuration when executingterraform initcommand components.terraform.auto_generate_backend_file- if set to
true, Atmos automatically generates the Terraform backend file from the component configuration when executingterraform planandterraform applycommands components.terraform.plan.skip_planfileif set to
true, Atmos will skip passing the-out=FILENAMEflag when executing theterraform plancommand. Set it totruewhen using Terraform Cloud since the-outflag is not supported. Terraform Cloud automatically stores plans in its backend
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:
terraformcomponents.terraformcomponents.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
}