So our friend Docker comes around for another usecase.

Run Terraform (any version) from Docker

In this example, we will try and configure Terraform 1.4.0 through Docker, so that we don’t need to install it on our host system.

1
alias terraform14='docker run --rm -it -w $PWD:$PWD -v $PWD:$PWD hashicorp/terraform:1.4.0'

To use it, we simply run a Terraform command:

1
terraform14 -version

Next let’s try another Terraform version as well

1
alias terraform15='docker run --rm -it -w $PWD:$PWD -v $PWD:$PWD hashicorp/terraform:1.5.0'

To use it, like before:

1
terraform15 -version

Run both versions next to one another

You can even run both versions next to one another, as proof:

1
terraform14 -version && terraform15 -version

The output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Terraform v1.4.0
on linux_amd64

Your version of Terraform is out of date! The latest version
is 1.6.6. You can update by downloading from https://www.terraform.io/downloads.html


Terraform v1.5.0
on linux_arm64

Your version of Terraform is out of date! The latest version
is 1.6.6. You can update by downloading from https://www.terraform.io/downloads.html