Last active
October 24, 2025 16:41
-
-
Save guitarrapc/371018c583e409990daba76df7f062f5 to your computer and use it in GitHub Desktop.
Run setup-terraform based on required_versions written on versions.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ./aws/versions.tf | |
| terraform { | |
| required_providers { | |
| aws = { | |
| version = "= 5.55.0" | |
| source = "hashicorp/aws" | |
| } | |
| } | |
| required_version = "~> 1.8.0" # use latest 1.8.x | |
| # required_version = "= 1.8.4" # use 1.8.4 | |
| backend "remote" { | |
| organization = "foo" | |
| hostname = "app.terraform.io" | |
| workspaces { | |
| name = "foo" | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # .github/workflows/workflow.yaml | |
| runs: | |
| steps: | |
| # checkout and any requirement | |
| - name: Get terraform version from .terraform-version | |
| shell: bash | |
| id: terraform-version | |
| run: | | |
| required_version=$(grep -E 'required_version\s*=\s*"([^"]+)"' "versions.tf" | sed -n 's/.*required_version\s*=\s*"\([^"]*\)".*/\1/p') | |
| echo "value=$required_version" | tee -a "${GITHUB_OUTPUT}" | |
| working-directory: ./aws | |
| - uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: ${{ steps.terraform-version.outputs.value }} # "~> 1.8.0" | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice!