In this Terraform installation script, we have specified the version number of Terraform to be installed.
If you want to install the latest version without having to know the version number, it is also possible to dynamically retrieve the version number of the latest version using the following API: https://checkpoint-api.hashicorp.com/v1/check/terraform. This retrieves information about the current version of Terraform.
The following screenshot shows our current version:
Note that the current_version property, which contains the latest Terraform version, is a value.
With this API, we can perfectly modify the first line of the installation script with the following code:
TERRAFORM_VERSION=$(curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r .current_version)
....
The complete script for installing Terraform with this block is available at https://github.com/PacktPublishing/Terraform-Cookbook/blob/master/CHAP01/install_terraform_linux_v2...