[Bash] Terraform install

To make sure the latest version of terraform is used when applying IaC code (mostly on a local Linux terminal) this bash script comes in handy !

The script is designed to automate the installation and update process of Terraform (binary).
What does the script do:

  1. A log file is created with a timestamp in its name.
  2. The script checks if jq, a command-line JSON processor, is installed. If not, it installs jq.
  3. It fetches the latest version of Terraform from HashiCorp’s Checkpoint API.
  4. If Terraform is already installed, it compares the installed version with the latest version. If they differ, the script renames the old binary and highlights the change.
  5. The script then downloads the latest Terraform binary, unzips the downloaded file, and moves the new binary to the system location.
  6. Finally, it verifies the installation by printing the installed version of Terraform. All actions are logged.

Below Bash Code will install or update Terraform (File: install_terraform.sh)

Output (example) of this bash script

This can also be done with python (see future post !)