Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Commit 7825a4c

Browse files
nozaqsudomateo
nozaq
authored andcommitted
Support to use the latest version of Terraform (#123)
* Support to use the latest version of Terraform Automatically download the latest version when tf_actions_version set to latest. * Use the JSON endpoint instead of parsing HTML * Abort if failed to resolve the latest version * Update README about `latest` tfVersion value
1 parent 250dd1c commit 7825a4c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ This was a simplified example showing the basic features of these Terraform GitH
7070
Inputs configure Terraform GitHub Actions to perform different actions.
7171

7272
* `tf_actions_subcommand` - (Required) The Terraform subcommand to execute. Valid values are `fmt`, `init`, `validate`, `plan`, and `apply`.
73-
* `tf_actions_version` - (Required) The Terraform version to install and execute.
73+
* `tf_actions_version` - (Required) The Terraform version to install and execute. If set to `latest`, the latest stable version will be used.
7474
* `tf_actions_cli_credentials_hostname` - (Optional) Hostname for the CLI credentials file. Defaults to `app.terraform.io`.
7575
* `tf_actions_cli_credentials_token` - (Optional) Token for the CLI credentials file.
7676
* `tf_actions_comment` - (Optional) Whether or not to comment on GitHub pull requests. Defaults to `true`.

src/main.sh

+10
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ EOF
6464
}
6565

6666
function installTerraform {
67+
if [[ "${tfVersion}" == "latest" ]]; then
68+
echo "Checking the latest version of Terraform"
69+
tfVersion=$(curl -sL https://releases.hashicorp.com/terraform/index.json | jq -r '.versions[].version' | grep -v '[-].*' | sort -rV | head -n 1)
70+
71+
if [[ -z "${tfVersion}" ]]; then
72+
echo "Failed to fetch the latest version"
73+
exit 1
74+
fi
75+
fi
76+
6777
url="https://releases.hashicorp.com/terraform/${tfVersion}/terraform_${tfVersion}_linux_amd64.zip"
6878

6979
echo "Downloading Terraform v${tfVersion}"

0 commit comments

Comments
 (0)