I'm start using Terraform and I'm following the project updates on his Github repository.
I see new releases are available on releases section:
https://github.com/hashicorp/terraform/releases
I installed Terraform tool following the steps:
https://www.terraform.io/intro/getting-started/install.html
The new releases are a zip file with base code but I want to know how I can install it on my computer (OSX). What I downloaded when I installed for the first time was a zip file with just a "terraform" file as unix executable.
How I can generate this Unix executable from the zip available on the github releases section?
Any idea?
Thank you!
If you use Homebrew on MacOS already, you can install Terraform simply by
$ brew install terraform
and upgrade by
$ brew upgrade terraform
In fact, you might be interested in letting Homebrew also control other tools:
$ brew install awscli
$ brew install packer
$ brew cask install docker
$ brew cask install virtualbox
$ brew cask install vagrant
There are packages for each OS available on the Downloads Page.
Pick the appropriate package for your OS and download the zip file.
Extract the contents of the zip file, which should be a single terraform binary, into some reasonable location that's in your PATH (e.g. /usr/local/bin).
Add execute permissions: e.g. chmod u+x /usr/local/bin/terraform.
Run terraform and make sure you see the help text.
You could download the binary :
wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip
then :
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip
then :
mv terraform /usr/local/bin/
make sure to change ${TERRAFORM_VERSION} by the version you want to install
exemple :
0.13.2
**TLDR:
for Installation - brew install terraform
for Upgrade - brew upgrade terraform
for Verification - terraform --version
i'm new to using terraform, but to use terraform with multiple versions i use tfenv as terraform version manager
tfenv command
$ tfenv
tfenv 2.2.3
Usage: tfenv <command> [<options>]
Commands:
install Install a specific version of Terraform
use Switch a version to use
uninstall Uninstall a specific version of Terraform
list List all installed versions
list-remote List all installable versions
version-name Print current version
init Update environment to use tfenv correctly.
pin Write the current active version to ./.terraform-version
terraform currently i use
$ terraform -version
Terraform v1.1.9
on linux_amd64
list of terraform i have
$ tfenv list
1.2.0-rc2
* 1.1.9 (set by /home/takimi/.tfenv/version)
change terraform version
$ tfenv use 1.2.0-rc2
and if you want to use another terraform version you just install it with command tfenv install <terraform version>
Adding this response for the sake of completeness.
Hashicorp came up with their own brew taps for all Hashicorp products for MacOS platforms.
to upgrade ...
brew upgrade hashicorp/tap/{vault|consul|nomad|terraform|packer}
to install ...
brew install hashicorp/tap/{vault|consul|nomad|terraform|packer}
Reference : https://www.hashicorp.com/blog/announcing-hashicorp-homebrew-tap
This is detailed in the repository README under 'Developing Terraform' HERE
Essentially...
Ensure you've installed the GO programming language (version 1.7+ at the time of writing).
Create a GO workspace directory.
Create the $GOPATH environment variable pointing to the GO workspace directory you just created.
Add $GOPATH/bin to your $PATH
Clone the Terraform repo (or extract zip) to $GOPATH/src/github.com/hashicorp/terraform
Run make dev within the Terraform repo.
The Terraform binary should be created in $GOPATH/bin
I would recommend you follow the steps in the README as opposed to what I've written above it's comprehensive and may change.
You shouldn't need to do any of this unless your actively developing Terraform, otherwise stick with the installation method in the getting started guide.
To work with multiple Terraform versions, I'm using tfswitch. This allows you to switch between the terraform versions which makes things much easier.
You can find the documentation here.
I was able to use this tool to manage terraform versions: https://github.com/Zordrak/tfenv. The first step was to remove the existing installation with: rm '/usr/local/bin/terraform'
You could use something like asdf or tfenv to manage the terraform binaries.
Gives you the advantage of having the option to use different version per project if required.
$sudo apt-get upgrade
it will work in linux if you have setup right path for terraform
Related
I installed an older version of terraform and the binary is in my downloads, how do I move it to another location? have to /opt/homebrew/Cellar/tfenv/3.0.0/versions/1.0.0/terraform
I used the method here: https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli
but I get: terraform is not a directory
think about using tfenv if you want to maintain different terraform versions in same PC.
By your path, it seems that you are using homebrew as a package manager.
Use these steps to install any version of terraform.
Install tfenv
brew install tfenv
List the available versions of terraform via tfenv (optional)
## To view all the available versions via tfenv.
tfenv list-remote
## tfenv list-remote | head -n <number_of_last_terraform_versions_you_want_to_list>
tfenv list-remote | head -n 20 ## example
To Install the required terraform version via tfenv
## tfenv install <terraform_version_you_want>
tfenv install 1.3.7
Switch to the version you installed via tfenv in the past or the last step.
## tfenv use <terraform_version_you_want>
tfenv use 1.3.7
If I install Terraform via brew install terraform#0.12 , it installed latest version 0.12.31.
And then to use it I run command alias terraform=$(brew config | awk '/HOMEBREW_PREFIX:/ { print $2 }')/opt/terraform#0.12/bin/terraform.
But I need to use not the latest version, I want to use 0.12.29.
And I can install it via
brew install tfenv
tfenv install 0.12.29
tfenv use 0.12.29
But I don't know how to specify this version ( 0.12.29 ) in alias terraform=.
Have you heard of this project? https://tfswitch.warrensbox.com/Quick-Start/
It makes adjusting the current version of terraform a lot easier.
Same for terragrunt https://warrensbox.github.io/tgswitch/additional.html
I want to completely remove terraform v0.11.14 from my ubuntu 18 and install the new version. I'm unable to find any document or articles on web about this..
See How to uninstall terraform and install newer version of terraform on windows 10 linux subsystem?
To install it you typically copy the binary to /usr/local/bin, so to uninstall it just delete the binary from the installation location. If you don't know the the location, just run 'which terraform' to find it.
I have a lot of Terraform modules written in Terraform 0.11 using gcp-provider of Terraform and want to upgrade the same to Terraform 0.12.
For this purpose, I need to keep both the versions installed on my system and use the version according to the version the module is written in.
I will go one by one in every module and upgrade the module using terraform 0.12upgrade to be compatible with Terraform 0.12 as per this documentation.
How to safely keep two versions of Terraform in one System?
I use Ubuntu 18.04 and I achieved this safely following the below steps. Similar steps can be followed to do the same on any Linux distro (making sure you are downloading the compatible binary. Confirm here)
NOTE Running the following commands as root or sudo user
Create directories to keep the Terraform binaries
$ mkdir -p /usr/local/tf
$ mkdir -p /usr/local/tf/11
$ mkdir -p /usr/local/tf/12
Download the binaries for both the versions
Download and extract the binary for Terraform 0.11 in a separate directory:
$ cd /usr/local/tf/11
$ wget https://releases.hashicorp.com/terraform/0.11.14/terraform_0.11.14_linux_amd64.zip
$ unzip terraform_0.11.14_linux_amd64.zip
$ rm terraform_0.11.14_linux_amd64.zip
Download and extract the binary for Terraform 0.12 in a separate directory:
$ cd /usr/local/tf/12
$ wget https://releases.hashicorp.com/terraform/0.12.20/terraform_0.12.20_linux_amd64.zip
$ unzip terraform_0.12.20_linux_amd64.zip
$ rm terraform_0.12.20_linux_amd64.zip
Create symlinks for both the Terraform versions in /usr/bin/ directory:
ln -s /usr/local/tf/11/terraform /usr/bin/terraform11
ln -s /usr/local/tf/12/terraform /usr/bin/terraform12
# Make both the symlinks executable
chmod ugo+x /usr/bin/terraform*
Calling different versions
Now, command terraform11 invokes version 0.11 and terraform12 invokes version 0.12
Example:
$ terraform11
$ terraform12
NOTE
Keeping the binaries in separate directories helps to separate their plugins as well without disturbing each other.
I'd highly recommend the tfenv tool. It sanely and easily can be used to manage multiple terraform installations. It's familiar if you've ever used nvm (for nodejs) or rvm (for ruby).
You can even add a .terraform-version file to your modules and the tool will automatically switch terraform versions for you when you cd into a module.
Make your life easy and install tfswitch. It takes care of installing and switching between versions you need; and it works like a magic.
If using multiple environments with terraform, tfenv would be the best tool to use. I initially had the same error and was able to run tfenv use version-number and it solved my issue. For background, I use terraform for personal and work projects on the same computer.
Why, when I run terraform -v do I get:
Terraform v0.9.6
Your version of Terraform is out of date! The latest version
is 0.9.7. You can update by downloading from www.terraform.io
i.e. implying the latest version is 0.9.7 BUT, at the time of this post (and when I ran the terraform -v command) https://www.terraform.io/ says 0.9.8 as does brew via http://brewformulas.org/Terraform
Install the required binary package (depending upon your OS) from Download page. https://github.com/hashicorp/terraform/releases
Unzip the .zip file to the bin directory as per your OS
For mac
unzip terraform_0.9.11_darwin_amd64.zip -d /usr/local/bin
Now check the terraform version:
terraform version
Terraform v0.9.1