Run any version of Terrform using Docker

0 min read 159 words

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
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags