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.
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:
terraform14 -version
Next let’s try another Terraform version as well
alias terraform15='docker run --rm -it -w $PWD:$PWD -v $PWD:$PWD hashicorp/terraform:1.5.0'
To use it, like before:
terraform15 -version
Run both versions next to one another
You can even run both versions next to one another, as proof:
terraform14 -version && terraform15 -version
The output:
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