Terraform Version Management#
Atlantis resolves and downloads Terraform (and OpenTofu) binaries on demand. At its core, the system answers: "given a requested version, return a path to a valid binary β downloading it if necessary." The key types are in server/core/terraform/.
Version Selection#
Atlantis determines which binary version to use in precedence order:
terraform_versioninatlantis.yamlβ highest priorityrequired_versionin Terraform/OpenTofu HCL β exact pin (= x.y.z) or version constraint (~> 1.2,>= 1.2.0)--default-tf-versionserver flag β fallback if neither of the above resolves- Terraform binary in
$PATHβ used as default if--default-tf-versionis unset
Version constraints in HCL are resolved against the live release index. Atlantis selects the highest version satisfying the constraint . When downloads are disabled, only exact version pins (= x.y.z or bare x.y.z) are accepted β range constraints are skipped .
Download Architecture#
The download path runs through two layers:
Distribution interface (server/core/terraform/distribution.go) β abstracts the two supported distributions:
DistributionTerraformβ wrapshc-install+ HashiCorp's release APIDistributionOpenTofuβ wrapstofudl
Downloader interface (server/core/terraform/downloader.go) β called by the distribution to perform the actual install:
TerraformDownloaderuseshc-install'sreleases.ExactVersion, passingApiBaseURL= the configured download URL. After install, the binary is renamed fromterraformβterraform{version}to match Atlantis's naming convention.TofuDownloaderusestofudl.Download()and writestofu{version}to disk.
The orchestration lives in ensureVersion (terraform_client.go). The lookup order before triggering a download:
- In-memory
versionsmap - Binary named
{binName}{version}found in$PATH - Binary found in
binDiron disk (survives Atlantis restarts)
If the binary is found but fails execution validation (terraform version returns an error), Atlantis automatically re-downloads a fresh copy (introduced in PR #6454). Only binaries managed within binDir are deleted; binaries found in $PATH are left untouched .
Key Server Flags#
| Flag | Default | Purpose |
|---|---|---|
--default-tf-version | (none) | Version to download at startup |
--default-tf-distribution | terraform | terraform or opentofu |
--tf-download | true | Allow runtime downloads; set false for air-gapped installs |
--tf-download-url | https://releases.hashicorp.com | Base URL for Terraform downloads β override for custom mirrors |
The --tf-download-url flag is passed as ApiBaseURL directly to hc-install's ExactVersion installer , so any HTTP server serving the standard HashiCorp release artifact layout can act as a mirror.
Note: Constraint resolution via
ResolveConstraintalways hits the public HashiCorp or OpenTofu registry API regardless of--tf-download-url. Custom mirrors only affect binary artifact downloads, not version listing.
Air-Gapped Environments#
Set --tf-download=false to prevent any outbound download attempts . In this mode:
- Only exact version pins in
required_versionare honored . - Binaries must be pre-staged either in
$PATH(namedterraform{version}/tofu{version}) or inbinDir. - The error when a version is missing:
"could not find {bin} version {v} in PATH or {binDir}, and downloads are disabled".
For container deployments, Atlantis publishes -slim image variants (e.g. alpine-slim, debian-slim) that ship without any pre-bundled Terraform or OpenTofu binaries (PR #6831). Operators can mount or copy binaries in and set --tf-download=false.
OpenTofu Distribution#
Switch the server default with --default-tf-distribution=opentofu. Projects can also override per-project in atlantis.yaml via terraform_distribution: opentofu .
When the effective distribution is OpenTofu, Atlantis reads required_version from .tofu and .tofu.json files in addition to .tf / .tf.json, with .tofu taking precedence over a same-basename .tf . The terraform-config-inspect library (used for Terraform distribution) does not read .tofu files .
Known limitation: --autoplan-modules dependency indexing does not yet fully support .tofu / .tofu.json files for module source blocks .
Primary Source Files#
| File | Role |
|---|---|
server/core/terraform/distribution.go | Distribution interface + Terraform/OpenTofu implementations |
server/core/terraform/downloader.go | Downloader interface + TerraformDownloader / TofuDownloader |
server/core/terraform/tfclient/terraform_client.go | ensureVersion, DefaultClient, command execution |
cmd/server.go | Flag definitions and defaults |
runatlantis.io/docs/terraform-versions.md | User-facing documentation |