This is one of a suite of terraform related actions - find them at POps-Rox/tf-gh-actions.
This action uses the terraform validate command to check that a terraform configuration is valid.
This can be used to check that a configuration is valid before creating a plan.
Failing GitHub checks will be added for any problems found.
If the terraform configuration is not valid, the build is failed.
-
pathPath to the terraform root module
- Type: string
- Optional
- Default: The action workspace
-
workspaceTerraform workspace to use for the
terraform.workspacevalue while validating. Note that for remote operations in Terraform Cloud/Enterprise, this is alwaysdefault.Also used for discovering the terraform version to use, if not otherwise specified. See POps-Rox/tf-gh-actions/terraform-version for details.
- Type: string
- Optional
- Default:
default
-
backend_configList of terraform backend config values, one per line. This is used for discovering the terraform version to use, if not otherwise specified. See POps-Rox/tf-gh-actions/terraform-version for details.
with: backend_config: token=${{ secrets.BACKEND_TOKEN }}
- Type: string
- Optional
-
backend_config_fileList of terraform backend config files to use, one per line. This is used for discovering the terraform version to use, if not otherwise specified. See POps-Rox/tf-gh-actions/terraform-version for details. Paths should be relative to the GitHub Actions workspace
with: backend_config_file: prod.backend.tfvars
- Type: string
- Optional
-
failure-reasonWhen the job outcome is
failurebecause the validation failed, this will be set to 'validate-failed'. If the job fails for any other reason this will not be set. This can be used with the Actions expression syntax to conditionally run a step when the validate fails.
-
TERRAFORM_CLOUD_TOKENSAPI tokens for terraform cloud hosts, of the form
<host>=<token>. Multiple tokens may be specified, one per line. These tokens may be used for fetching required modules from the registry, and discovering the terraform version to use from a TFC/E workspace.e.g for terraform cloud:
env: TERRAFORM_CLOUD_TOKENS: app.terraform.io=${{ secrets.TF_CLOUD_TOKEN }}
With Terraform Enterprise or other registries:
env: TERRAFORM_CLOUD_TOKENS: | app.terraform.io=${{ secrets.TF_CLOUD_TOKEN }} terraform.example.com=${{ secrets.TF_REGISTRY_TOKEN }}
- Type: string
- Optional
-
TERRAFORM_SSH_KEYA SSH private key that terraform will use to fetch git module sources.
This should be in PEM format.
For example:
env: TERRAFORM_SSH_KEY: ${{ secrets.TERRAFORM_SSH_KEY }}
- Type: string
- Optional
-
TERRAFORM_PRE_RUNA set of commands that will be run prior to
terraform init. This can be used to customise the environment before running terraform.The runtime environment for these actions is subject to change in minor version releases. If using this environment variable, specify the minor version of the action to use.
The runtime image is currently based on
debian:bullseye, with the command run usingbash -xeo pipefail.For example:
env: TERRAFORM_PRE_RUN: | # Install latest Azure CLI curl -skL https://aka.ms/InstallAzureCLIDeb | bash # Install postgres client apt-get install -y --no-install-recommends postgresql-client
- Type: string
- Optional
-
TERRAFORM_HTTP_CREDENTIALSCredentials that will be used for fetching modules sources with
git::http://,git::https://,http://&https://schemes.Credentials have the format
<host>=<username>:<password>. Multiple credentials may be specified, one per line.Each credential is evaluated in order, and the first matching credentials are used.
Credentials that are used by git (
git::http://,git::https://) allow a path after the hostname. Paths are ignored byhttp://&https://schemes. For git module sources, a credential matches if each mentioned path segment is an exact match.For example:
env: TERRAFORM_HTTP_CREDENTIALS: | example.com=myuser:${{ secrets.HTTPS_PASSWORD }} github.com/POps-Rox/tf-gh-actions.git=pops-rox-actions:${{ secrets.ACTIONS_PAT }} github.com/POps-Rox=pops-rox:${{ secrets.POPS_ROX_PAT }} github.com=graham:${{ secrets.GITHUB_PAT }}
- Type: string
- Optional
This example workflow runs on every push and fails if the terraform configuration is invalid.
on: [push]
jobs:
validate:
runs-on: ubuntu-latest
name: Validate terraform
steps:
- name: Checkout
uses: actions/checkout@v3
- name: terraform validate
uses: POps-Rox/tf-gh-actions/terraform-validate@v1
with:
path: my-terraform-configThis example executes a run step only if the validation failed.
on: [push]
jobs:
validate:
runs-on: ubuntu-latest
name: Validate terraform
steps:
- name: Checkout
uses: actions/checkout@v3
- name: terraform validate
uses: POps-Rox/tf-gh-actions/terraform-validate@v1
id: validate
with:
path: my-terraform-config
- name: Validate failed
if: ${{ failure() && steps.validate.outputs.failure-reason == 'validate-failed' }}
run: echo "terraform validate failed"