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:
- A log file is created with a timestamp in its name.
- The script checks if
jq
, a command-line JSON processor, is installed. If not, it installsjq
. - It fetches the latest version of Terraform from HashiCorp’s Checkpoint API.
- 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.
- The script then downloads the latest Terraform binary, unzips the downloaded file, and moves the new binary to the system location.
- 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 !)