asdf manage multiple version Terraform with GCP

Last update: 2022-08-03

We will use asdf as version manager with Terraform.

Installation

I will use Homebrew (Mac) + zsh to demonstrate.

# http://asdf-vm.com/guide/getting-started.html#_3-install-asdf

## Installation
brew install asdf

## Add asdf to zshrc
echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc

Install Terraform dependencies

asdf plugin-add terraform https://github.com/asdf-community/asdf-hashicorp.git
asdf plugin-add terraform-ls https://github.com/asdf-community/asdf-hashicorp.git

asdf install terraform 1.2.6
asdf global terraform 1.2.6

Install Google Cloud CLI

brew install --cask google-cloud-sdk
# or
curl https://sdk.cloud.google.com | bash

Google Cloud CLI login

gcloud auth application-default login

Try to do terraform init and plan

# CD under project root directory

# Init terraform
terraform init

# Check changes
terraform plan