Skip to content

Commit

Permalink
Export terraform_version as an output
Browse files Browse the repository at this point in the history
  • Loading branch information
stv-io committed Jan 19, 2024
1 parent b6c5e07 commit c154ec3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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) .."
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .."
Expand All @@ -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!"
Expand Down

0 comments on commit c154ec3

Please sign in to comment.