Skip to main content

How to Switch Versions of Terraform

Problem

You need to use (or want to upgrade to) the latest version of terraform for a component you’re working on, but do not want to affect other components.

Solution

Install Desired Version of Terraform

First, make sure you’ve installed the latest version of terraform in Geodesic by following our guide How to Upgrade or Install Versions of Terraform.

Switch Terraform Versions (Local Geodesic Shell)

tip

You can pin the version of terraform using update-alternatives as well as in the component configuration.

To see Versions supported Check either the Dockerfile, or run ls /usr/share/terraform/ on your geodesic shell

update-alternatives --set terraform /usr/share/terraform/${Major.Minor}/bin/terraform

Terraform Releases

https://github.com/hashicorp/terraform/releases

Switch Terraform Versions for a Component on a stack

Update the terrafrom component’s settings in <ProjectDir>/stacks/globals.yaml to set the default atmos terraform version and the spacelift version. an example configuration would look like

components:
terraform:
<component>:
settings:
spacelift:
terraform_version: "0.14" # Version of terraform used by Spacelift
command: "/usr/bin/terraform-0.14" # Version of terraform used by Atmos on the command line

This would then set the spacelift version and local atmos version to use a specific terraform Major.Minor version for that component.

NOTE:

the major.minor.patch versions are defined (and installed) in the Dockerfile of the Project.

caution

Spacelift installs the version of terraform specified in terraform_version and does not use the package distributed in the container. The terraform_version must be defined in the spacelift/default.auto.tfvars file.

Spacelift Version Mapping

By convention, we have components pin only to major versions of terraform and not patch releases. The precise version of terraform used is configured in the spacelift/default.auto.tfvars file. Note, that the spacelift component is not yet configurable via stack configurations and all tuning is done via the default.auto.tfvars file.

caution

Spacelift does not always support the bleeding edge patch releases of terraform. Reach out to spacelift if the version you need is not available and they’ll let you know the ETA.

terraform_version = "0.14.11"  # Default version of terraform to use
terraform_version_map = { # Map major versions to precise versions of terraform
"0.14" = "0.14.11"
"0.15" = "0.15.5"
"1.0" = "1.0.9"
}