x89
x89

Reputation: 3460

unable to update terraform version

I already have the latest version in my provider.tf files:

  required_providers {
    archive = {
      source  = "hashicorp/archive"
      version = "2.2.0"
    }
    aws     = {
      source  = "hashicorp/aws"
      version = "3.72.0"
    }
  }

However, when I check terraform versionon my terminal, I get this:

Terraform v1.0.7
on darwin_amd64
+ provider registry.terraform.io/hashicorp/archive v2.2.0
+ provider registry.terraform.io/hashicorp/aws v3.72.0

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

I already tried terraform init -upgradebut that didn't make a difference either.I also manually downloaded terraform's new version from the website but my terminal still shows 1.0.7.

Due to the old Terraform version, I face other errors. How can I update to the latest version using the terminal?

Upvotes: 2

Views: 9745

Answers (2)

Sysanin
Sysanin

Reputation: 1795

In my case it helped to unlink tfenv and link terraform via brew to get the upgraded version (tested on mac m1).

Originally it was linked to previous installed version:

terraform -v

Terraform v1.5.6
on darwin_arm64

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

When I tried to upgrade via brew it said it was already updated to the latest:

brew upgrade terraform

Warning: hashicorp/tap/terraform 1.6.1 already installed

Solution with unlinking:

brew unlink tfenv
Unlinking /opt/homebrew/Cellar/tfenv/3.0.0... 9 symlinks removed.
brew link terraform
Linking /opt/homebrew/Cellar/terraform/1.6.1... 1 symlinks created.
terraform -v
Terraform v1.6.1
on darwin_arm64

Hope it helps to anyone who is looking for solving similar issue.

Upvotes: 0

Marko E
Marko E

Reputation: 18138

There is a difference between providers and terraform binary. With the command you are using you would update the provider and module versions. From your question I understand you downloaded the binary to your Mac. That of course is not enough. You have to replace the old binary with the new one. The easiest way to do this is to run:

echo $PATH

This should give you information about where to put the new binary so the system knows where to look for it. The output should look similar to:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Then subsequently run:

which terraform

It should show you where the terraform binary is located and in most cases it matches one of the locations listed in PATH environment variable. Example:

/usr/local/bin/terraform

Then, unzip the file you downloaded and copy it over to the location of the old binary. Note that this will delete the old version.

There are better ways to handle multiple terraform versions though. One of those is using tfenv [1].

Another way to install (and override) versions of terraform is to follow the guide here [2] and use homebrew which is MacOS' package manager, but in short the commands are:

brew tap hashicorp/tap
brew install hashicorp/tap/terraform

[1] https://github.com/tfutils/tfenv

[2] https://www.terraform.io/downloads

Upvotes: 9

Related Questions