Reputation: 18544
Use case
I have installed Terraform v0.11.13 via homebrew and as recommended by terraform I want to ugprade to version v0.11.14 before doing the major upgrade to v0.12.0.
The problem
When I run brew upgrade terraform
or download the Mac package from the terraform website it would immediately update my terraform version to v0.12.0 I think.
So how can I upgrade to v0.11.14 instead?
Upvotes: 173
Views: 168708
Reputation: 420
Try to use tenv for that, the command is similar:
tenv tf install 0.11.14
tenv tf use 0.11.14
tenv works in a more predictable way
Upvotes: 0
Reputation: 401
Your version is quite old now but here is my suggestion:
brew uninstall terraform
Use Terraform's official binaries to install v0.11.14: Homebrew does not maintain older versions directly, so you can manually download and install the required version.
Download binary
curl -O https://releases.hashicorp.com/terraform/0.11.14/terraform_0.11.14_darwin_amd64.zip
unzip terraform_0.11.14_darwin_amd64.zip
sudo mv terraform /usr/local/bin/terraform
5 Verify the installation:
terraform -v
Above is for direct installation method
You can follow tfenv
approach to get multiple version in use.
Here is quick commands
#Download tfenv for Mac
brew install tfenv
#Download required version
tfenv install 0.11.14
#Set default version
tfenv use 0.11.14
#Optional you can set version globally as well
tfenv use 1.0.11 --global
Upvotes: 2
Reputation: 31
#Terraform installation through downloaded binary with respect to a specific version
There are cases when your organisation is using a particular terraform version & you know that current terraform version is way latest than the one in your organisation is using and you are tasked to use the same without the latest version. so that you can use below steps to update the binary versions as in when needed under /usr/bin
wget https://releases.hashicorp.com/terraform/1.6.5/terraform_1.6.5_linux_amd64.zip
wget https://releases.hashicorp.com/terraform/1.6.5/terraform_1.6.5_SHA256SUMS
SHA256SUM terraform_1.6.5_linux_amd64.zip
mv terraform_1.6.5_linux_amd64.zip terraform.zip
unzip terraform.zip
sudo mv terraform /usr/bin
terraform version
Just in case a video based handson reference is needed - #https://www.youtube.com/watch?v=1vBJNjv9h8I
Upvotes: 0
Reputation: 3064
I can recommend checking out tenv.
tenv
allows you to manage not only Terraform versions, but also OpenTofu and Terragrunt - one simple tool for all three binaries.
Upvotes: 3
Reputation: 37630
Especially when playing around with Terraform 0.12 betas, I learned to love tfenv.
After installation (via brew install tfenv
on MacOS), this allows you to easily discover, install and activate any Terraform version:
$ tfenv list-remote
0.12.0
0.12.0-rc1
0.12.0-beta2
0.12.0-beta1
0.12.0
0.11.14
...
$ tfenv install 0.11.14
[INFO] Installing Terraform v0.11.14
[INFO] Downloading release tarball from https://releases.hashicorp.com/terraform/0.11.14/terraform_0.11.14_darwin_amd64.zip
...
[INFO] Installation of terraform v0.11.14 successful
[INFO] Switching to v0.11.14
[INFO] Switching completed
If you want to manually switch to a different version:
$ tfenv use 0.12.0
[INFO] Switching to v0.12.0
[INFO] Switching completed
Alternatively, adding .terraform-version
file makes tfenv
automatically switch to the right version for a given directory and it will even take care of auto-installing the correct version if not already installed.
Upvotes: 446
Reputation: 46
My two cents
There's a tool that works pretty much like tfenv
but it also handles many other software
mise-en-place: https://mise.jdx.dev
You can manage versions for terraform terragrunt go java node python ruby .net awscli postgres redis mongodb etc etc via plugins
Full list of plugins: https://github.com/mise-plugins/registry/blob/main/README.md
Hope you like it
Upvotes: 0
Reputation: 71
below command will show all the available versions of terraform
sudo apt policy terraform
Install the desired version:
sudo apt-get install terraform=1.4.4-1
If you have a old version already, then uninstall it and run above commands
sudo apt remove terraform
Upvotes: 0
Reputation: 655
I realised that I was using remote execution with terraform cloud instead of local execution, Thus, even though I upgraded my local terraform to 1.3.7, my remote version remain 1.1.7 therefore I had update the remote version by simply selecting the appropriate version from my workspace settings and everything works.
Upvotes: 1
Reputation: 71
just use tfenv or tfswitch both tools are really good. good point is that if you have version requirements in terraform files when you do tfswitch it will automatically download and install version which you need.
https://tfswitch.warrensbox.com/
Upvotes: 1
Reputation: 2327
Easy and best way to do:-
# MacOS
brew install warrensbox/tap/tfswitch
# Linux
curl -L https://raw.githubusercontent.com/warrensbox/terraform-
switcher/release/install.sh | bash
then use Either one of command to change version-
1. tfswitch ==> you will see option to select version.
2. tfswitch 0.14.3 ==> this way
Upvotes: 5
Reputation: 487
There is a nice alternative to tfenv that I've been using for few years now - tfswitch.
# MacOS
brew install warrensbox/tap/tfswitch
# Linux
curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash
tfswitch VERSION_NUMBER
.version.tf
file..tfswitchrc
, .terrafom-version
- requires minimum setup and supports bash, zsh and fish.All in all it's a great and simple helper, would recommend this one.
Upvotes: 17
Reputation: 13
I have used TF since 0.6 and actively use many different versions on my workstation. I do this with direnv [https://direnv.net/] since that was available for quite a while, and it works well for managing the TF binary version within a dir, plus it allows me to pass env vars per dir into TF with little hassle.
Sample .envrc:
export AWS_PROFILE=prod
export PATH=/usr/local/terraform/terraform-0.12.20:$PATH
export TF_VAR_dd_api_key=REDACTED
export TF_VAR_dd_app_key=REDACTED
When I cd into the dir containing this .envrc, not only does it put the correct TF binary in my PATH, it also sets my AWS profile and in this case some DataDog API keys.
When I want to upgrade TF, I ensure I have the desired binary placed into the correct location and edit the .envrc so it is in PATH. Ideally, the .envrc is not pushed to Github since other people could have different setups, and especially API keys should not go into the repo.
I know it's a little old fashioned but it works great for me.
Upvotes: 1
Reputation: 111
Apart from the conventional solutions, an easy implementation to the required problem would be installing tfswitch. It can change terraform versions with only one command. Installation and usage guide is provided in the given link.
Note:
You can not downgrade to previous versions after the script has been initialised (terraform init
).
Upvotes: 7
Reputation: 631
For anyone looking to do the same without using homebrew:
$ wget https://releases.hashicorp.com/terraform/0.11.14/terraform_0.11.14_linux_amd64.zip
$ unzip terraform_0.11.14_linux_amd64.zip
$ chmod +x terraform
$ sudo mv terraform /usr/local/bin/
$ terraform --version
Source: https://titosoft.github.io/kvm/terraform-and-kvm/#installing-terraform
Upvotes: 47