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
OpenTofu 1.8+ Module Source Interpolation
OpenTofu 1.8.0 introduced support for variable interpolation in module source attributes, enabling dynamic module paths based on configuration. This feature is OpenTofu-specific and is not supported in HashiCorp Terraform.
Automatic Support
Atmos automatically detects when you're using OpenTofu (by checking if your command contains "tofu" or by executing the version command) and handles OpenTofu-specific syntax gracefully. No additional configuration is required.
Example: Dynamic Module Sources
variable "context" {
type = object({
build = object({
module_path = string
module_version = string
})
})
description = "Context for dynamic module loading"
}
module "dynamic_module" {
source = "${var.context.build.module_path}"
# Module inputs
name = "example"
}
components:
terraform:
my-component:
vars:
context:
build:
module_path: "./modules/example"
module_version: "v1.0.0"
How It Works
When you configure command: "tofu" in your atmos.yaml, Atmos:
-
Auto-detects OpenTofu using a two-tier strategy:
- Fast path: Checks if the executable basename contains "tofu"
- Slow path: Executes
<command> versionand checks for "OpenTofu" - Caches results for performance
-
Skips incompatible validation for known OpenTofu-specific features:
- Module source variable interpolation
- Other OpenTofu 1.8+ syntax extensions
-
Still catches real errors - Only skips validation for known OpenTofu patterns, ensuring actual syntax errors are still reported
Supported Command Patterns
Atmos recognizes OpenTofu through any of these command configurations:
command: "tofu"- Simple executable namecommand: "/usr/bin/tofu"- Absolute pathcommand: "/opt/homebrew/bin/tofu"- Homebrew installationcommand: "/Users/user/.asdf/shims/tofu"- asdf-managedcommand: "/path/to/custom/tofu"- Custom installation
Requirements for Module Source Interpolation
To use variable interpolation in module sources with OpenTofu, you must:
-
Configure the OpenTofu command:
atmos.yamlcomponents:
terraform:
command: "tofu" # or any path containing "tofu" -
Enable passing variables to init (required for module source interpolation):
atmos.yamlcomponents:
terraform:
init:
pass_vars: true -
Use OpenTofu 1.8.0 or later
Migration from Terraform
If migrating from HashiCorp Terraform to OpenTofu and want to use module source interpolation:
Before (Terraform - not supported):
# This will fail in Terraform
module "example" {
source = "${var.module_path}" # Error: Variables not allowed
}
After (OpenTofu 1.8+ - works automatically):
# This works in OpenTofu 1.8+ with Atmos auto-detection
module "example" {
source = "${var.module_path}" # Automatically supported
}
No configuration changes needed in Atmos - the auto-detection handles it automatically when command: "tofu" is configured.
Troubleshooting
If you encounter validation errors with OpenTofu-specific syntax:
-
Verify OpenTofu detection:
tofu version
# Should output: OpenTofu v1.8.x -
Check Atmos configuration:
components:
terraform:
command: "tofu" # Must contain "tofu" or be a path to tofu
init:
pass_vars: true # Required for module source interpolation -
Enable debug logging to see detection details:
export ATMOS_LOGS_LEVEL=Trace
atmos terraform plan my-component -s my-stack
For more details on this feature, see the OpenTofu 1.8.0 release notes.