diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c7a433f..2a7d9dc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,3 +63,18 @@ jobs: EOF tfswitch terraform --version + + export-version-as-output: + outputs: + terraform_version: ${{ steps.tfswitch-install.outputs.terraform_version }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup tfswitch + uses: ./ + id: tfswitch-install + - name: Install + run: | + tfswitch 1.7.0 + terraform --version + echo "Terraform ${{steps.tfswitch-install.outputs.terraform_version }} installed to $(which terraform) .." \ No newline at end of file diff --git a/README.md b/README.md index a0eac49..550c81a 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,29 @@ jobs: ... ``` +### Use specified version in terraform setup + +```yaml +jobs: + export-version-as-output: + outputs: + terraform_version: ${{ steps.tfswitch-install.outputs.terraform_version }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup tfswitch + uses: stv-io/action-tfswitch@v1 + - name: Install + id: tfswitch-install + run: | + tfswitch 1.6.4 + terraform --version + ... + - name: display version and path + run: | + echo "Terraform ${{steps.tfswitch-install.outputs.terraform_version }} installed to $(which terraform) .." +``` + ## Note This action unlinks the default installed terraform which is available in the [runner](https://github.com/actions/runner-images/tree/main). diff --git a/action.yml b/action.yml index 1eabeb8..713a348 100644 --- a/action.yml +++ b/action.yml @@ -17,7 +17,7 @@ runs: shell: bash run: | echo "Downloading install script .." - curl -sLo install.sh https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh + curl -sLo install.sh https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh echo "Configuring install script to be executable .." chmod 755 install.sh echo "Creating $HOME/.bin for tfswitch binary .." @@ -31,6 +31,8 @@ runs: tfswitch --version echo "Exporting PATH to GITHUB_PATH .." echo $HOME/.bin >> $GITHUB_PATH + echo "Exporting terraform version to GITHUB_OUTPUT as terraform_version.." + echo "terraform_version=$(terraform --version -json | jq -r .terraform_version)" >> "$GITHUB_OUTPUT" echo "Unlinking default version of terraform .." unlink /usr/local/bin/terraform echo "Done!"