Within my company we have a library of custom GitHub Actions that we are encouraged to use. One of those custom github actions is a wrapper around the terraform cli and it does a few useful things, including creating some TF_VAR env vars that will then be available to our terraform configurations.
- name: Terraform ${{ inputs.action }}
shell: bash
working-directory: ${{ inputs.directory }}
run: |
(${{ github.action_path }}/script-to-call-terraform.sh
env:
INPUT_ACTION: ${{ inputs.action }}
TF_VAR_squad: ${{ inputs.squad }}
TF_VAR_tribe: ${{ inputs.tribe }}
TF_VAR_repo: ${{ env.GITHUB_REPOSITORY_NAME }}
TF_LOG: ${{ inputs.log_level }}
Today I’ve been trying to use this custom github action to call terraform test
which is new in terraform v1.6.x Unfortunately when I do so it fails with:
tests/database.tftest.hcl... in progress
run "setup_tests"... fail
run "no_warehouse"... skip
run "with_warehouse"... skip
tests/database.tftest.hcl... tearing down
tests/database.tftest.hcl... fail
Failure! 0 passed, 1 failed, 2 skipped.
╷
│ Error: Variables not allowed
│
│ on <value for var.repo> line 1:
│ (source code not available)
│
│ Variables may not be used here.
╵
╷
│ Error: Variables not allowed
│
│ on <value for var.squad> line 1:
│ (source code not available)
│
│ Variables may not be used here.
╵
╷
│ Error: Variables not allowed
│
│ on <value for var.tribe> line 1:
│ (source code not available)
│
│ Variables may not be used here.
╵
Clearly this is failing because of the presence of environment variables:
- TF_VAR_tribe
- TF_VAR_squad
- TF_VAR_repo
I can of course reproduce the error locally by simply running:
TF_VAR_abc=xyz terraform test
My question is simply…why? Why does terraform test
balk when some TF_VAR_* vars exist?