Skip to content

fix(get-terraform-dir): Resolve error when multiple directories returned #200

fix(get-terraform-dir): Resolve error when multiple directories returned

fix(get-terraform-dir): Resolve error when multiple directories returned #200

Workflow file for this run

name: Lint
on:
pull_request:
types: [opened, synchronize]
branches: [main]
workflow_call:
inputs:
terraform-dir:
type: string
required: false
# Disable permissions for all available scopes
permissions: {}
jobs:
lint:
runs-on: ubuntu-latest
permissions:
contents: read
checks: write # not required (see slack) but produces an error in the logs
# https://trunkcommunity.slack.com/archives/C04GAE5EA5S/p1677846825881319?thread_ts=1676214812.584879&cid=C04GAE5EA5S
timeout-minutes: 10
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}-${{ inputs.terraform-dir }}
cancel-in-progress: true
steps:
- name: Checkout repository
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
with:
persist-credentials: true # lint fails to authenticate when false
- name: Setup tfswitch
if: ${{ inputs.terraform-dir != '' }}
uses: stv-io/action-tfswitch@b6c5e07f48a6de1934acf5e9c67bd3b21423e9e1 # v1.0.0
- name: Get tf version
if: ${{ inputs.terraform-dir != '' }}
id: tf-version
run: |
tfswitch --chdir=${{ inputs.terraform-dir }}
echo "TERRAFORM_VERSION=$(terraform --version -json | jq -r .terraform_version)" >> "$GITHUB_ENV"
- name: Setup Tofu
if: ${{ inputs.terraform-dir != '' }}
uses: opentofu/setup-opentofu@ae80d4ecaab946d8f5ff18397fbf6d0686c6d46a # v1.0.3
with:
tofu_version: ${{ env.TERRAFORM_VERSION }}
# Initialise terraform in the directory where terraform file have changed.
- name: Initialise Tofu
if: ${{ inputs.terraform-dir != ''}}
working-directory: ${{ inputs.terraform-dir }}
run: tofu init --backend=false
- name: Lint with trunk
if: ${{ always() }} # Run anyway, even if no terraform
uses: trunk-io/trunk-action@da67635060feab46c164bc130690e61864a5d13b # v1.1.13