Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active June 23, 2024 16:15
Show Gist options
  • Save guitarrapc/371018c583e409990daba76df7f062f5 to your computer and use it in GitHub Desktop.
Save guitarrapc/371018c583e409990daba76df7f062f5 to your computer and use it in GitHub Desktop.
Run setup-terraform based on required_versions written on versions.tf
# ./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"
}
}
}
# .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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment