diff --git a/.github/workflows/call-terraform-test.yaml b/.github/workflows/call-terraform-test.yaml index 5ec61c7..c309001 100644 --- a/.github/workflows/call-terraform-test.yaml +++ b/.github/workflows/call-terraform-test.yaml @@ -18,8 +18,12 @@ on: default: false required: true type: boolean + working-directory: + description: "Directory holding the Terraform configuration under test, relative to the repository root (for repositories where it is not at the root)" + default: "." + type: string test-directory: - description: "Directory containing tftest.hcl files" + description: "Directory containing tftest.hcl files, relative to working-directory" default: tests type: string verbose: @@ -41,8 +45,9 @@ jobs: fetch-depth: '0' - name: Run terraform test + working-directory: ${{ inputs.working-directory }} run: | terraform init terraform test \ -test-directory=${{ inputs.test-directory }} \ - ${{ inputs.verbose == 'true' && '-verbose' || '' }} + ${{ inputs.verbose && '-verbose' || '' }} diff --git a/.github/workflows/call-validate-terraform.yaml b/.github/workflows/call-validate-terraform.yaml index 7b1b569..937b4e9 100644 --- a/.github/workflows/call-validate-terraform.yaml +++ b/.github/workflows/call-validate-terraform.yaml @@ -22,6 +22,14 @@ on: default: false required: true type: boolean + working-directory: + description: "Directory holding the Terraform configuration, relative to the repository root (for repositories where it is not at the root)" + default: "." + type: string + fmt-check: + description: "Fail when files are not formatted (terraform fmt -check -diff -recursive). Off by default, which keeps the previous behaviour: fmt rewrites the runner's checkout and never fails" + default: false + type: boolean jobs: Terraform-Validate: @@ -33,9 +41,10 @@ jobs: steps: - name: Checkout code uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - run: | + - working-directory: ${{ inputs.working-directory }} + run: | terraform init - terraform fmt + terraform fmt ${{ inputs.fmt-check && '-check -diff -recursive' || '' }} terraform validate Terraform-Lint: @@ -47,6 +56,7 @@ jobs: steps: - name: Checkout code uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - run: | + - working-directory: ${{ inputs.working-directory }} + run: | ls -lta tflint --recursive