Configure OpenTofu
Atmos natively supports OpenTofu, similar to the way it supports Terraform. It's compatible with every version of opentofu and designed to work with multiple different versions of it concurrently, and can even work alongside with HashiCorp Terraform.
You will learn
- How to configure Atmos to use OpenTofu for Terraform components
- How to alias
terraformtotofuin Atmos - How to configure OpenTofu for only specific components
Please see the complete configuration options for Terraform, as they are the same for OpenTofu. We'll focus only on what's different in this document, in order to utilize OpenTofu. Keep in mind that Atmos does not handle the downloading or installation of OpenTofu; it assumes that any required binaries for the commands are already installed on your system.
Additionally, if using Spacelift together with Atmos, make sure you review the Spacelift Integration to make any necessary changes.
CLI Configuration
All the default configuration settings to support OpenTofu are defined in the Atmos CLI Configuration, 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/tofu" # or just `tofu`
# 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/tofu"
# 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)"
init:
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_INIT_PASS_VARS' ENV var, or '--init-pass-vars' command-line argument
pass_vars: true
components.terraform.command- The executable to be called by Atmos when running OpenTofu commands
components.terraform.base_path- The root directory where the OpenTofu components and configurations are located. This path serves as the starting point for resolving any relative paths within the OpenTofu 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.init.pass_varsif set to
true, Atmos automatically passes the generated varfile to thetofu initcommand using the--var-fileflag. OpenTofu supports passing a varfile toinitto dynamically configure backends
To make OpenTofu the default command when running "terraform", modify atmos.yaml to configure the following global settings:
components:
terraform:
# Use the `tofu` command when calling "terraform" in Atmos.
command: "/usr/bin/tofu" # or just `tofu`
# Optionally, specify a different path for OpenTofu components
base_path: "components/tofu"
Atmos consistently utilizes the terraform keyword across all configurations, rather than tofu or opentofu.
The term “Terraform” is used in this documentation to refer to generic concepts such as providers, modules, stacks, the
HCL-based domain-specific language and its interpreter.
Additionally, if you prefer to run atmos tofu instead of atmos terraform, you can configure an alias.
Just add the following configuration somewhere in the atmos.yaml CLI config file:
aliases:
tofu: terraform
Creating aliases for tofu only changes the CLI invocation of atmos terraform and does not directly
influence the actual command that atmos executes when running Terraform. Atmos strictly adheres to the
specific command set in the Stack configurations.
Stack Configuration for Components
Settings for Terraform or OpenTofu can also be specified in stack configurations, where they are compatible with inheritance. This feature allows projects to tailor behavior according to individual component needs.
While defaults for everything are defined in the atmos.yaml, the same settings, can be overridden by Stack configurations at any level:
terraformcomponents.terraformcomponents.terraform._component_
For instance, you can modify the command executed for a specific component by overriding the command parameter.
This flexibility is particularly valuable for gradually transitioning to OpenTofu or managing components that are
compatible only with HashiCorp Terraform.
components:
terraform:
vpc:
command: "/usr/local/bin/tofu-1.7"
Example: Provision a Terraform Component with OpenTofu
In the following examples, we'll assume that tofu is an Atmos alias for the terraform command.
aliases:
tofu: terraform
Once you've configured Atmos to utilize tofu — either by adjusting the default terraform.command in the atmos.yaml
or by specifying the command for an individual component — provisioning any component follows the same procedure as
you would typically use for Terraform.
For example, to provision a Terraform component using OpenTofu, run the following commands:
atmos tofu plan eks --stack=ue2-dev
atmos tofu apply eks --stack=ue2-dev
where:
eksis the Terraform component to provision (from thecomponents/terraformfolder)--stack=ue2-devis the stack to provision the component into
Short versions of all command-line arguments can be used:
atmos tofu plan eks -s ue2-dev
atmos tofu apply eks -s ue2-dev