|
| 1 | +# YAML Validation Action |
| 2 | + |
| 3 | +Validate your `dbt-config.yml` against the dbt Cloud Terraform YAML schema **before** running Terraform or supplying any dbt Cloud credentials. This catches typos, missing required fields, and structural errors early in your pull-request workflow. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The `validate` action is a composite GitHub Action shipped inside this repository. It uses [`check-jsonschema`](https://check-jsonschema.readthedocs.io/) to validate your YAML file against [`schemas/v1.json`](https://raw.githubusercontent.com/dbt-labs/terraform-dbtcloud-as-yaml/main/schemas/v1.json). |
| 8 | + |
| 9 | +- **No Terraform required** — no `terraform init`, no provider downloads |
| 10 | +- **No dbt Cloud credentials required** — purely structural validation |
| 11 | +- **Fast** — typically completes in under 30 seconds |
| 12 | +- **Clear error messages** — reports every violation with a JSON path so you know exactly what to fix |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## Quick Start |
| 17 | + |
| 18 | +```yaml title=".github/workflows/validate.yml" |
| 19 | +name: Validate dbt Cloud YAML |
| 20 | + |
| 21 | +on: |
| 22 | + push: |
| 23 | + pull_request: |
| 24 | + |
| 25 | +jobs: |
| 26 | + validate: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v4 |
| 30 | + - uses: dbt-labs/terraform-dbtcloud-as-yaml/validate@v1 |
| 31 | + with: |
| 32 | + file: dbt-config.yml # optional — this is the default |
| 33 | +``` |
| 34 | +
|
| 35 | +The job exits with code `1` and prints a structured error report when the file does not conform to the schema, causing your CI run to fail immediately — before any Terraform or credential steps run. |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +## Inputs |
| 40 | + |
| 41 | +| Input | Required | Default | Description | |
| 42 | +|-------|----------|---------|-------------| |
| 43 | +| `file` | No | `dbt-config.yml` | Path to the dbt Cloud YAML configuration file to validate, relative to the repository root. | |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## Example: Validate before Terraform Plan |
| 48 | + |
| 49 | +Add the validation step at the top of your existing Terraform CI workflow so bad YAML is caught before Terraform even initialises: |
| 50 | + |
| 51 | +```yaml title=".github/workflows/ci.yml" |
| 52 | +name: CI — Validate and Plan |
| 53 | +
|
| 54 | +on: |
| 55 | + pull_request: |
| 56 | + branches: [main] |
| 57 | + paths: |
| 58 | + - "dbt-config.yml" |
| 59 | + - "**.tf" |
| 60 | +
|
| 61 | +permissions: |
| 62 | + contents: read |
| 63 | + pull-requests: write |
| 64 | +
|
| 65 | +jobs: |
| 66 | + validate: |
| 67 | + name: Validate YAML |
| 68 | + runs-on: ubuntu-latest |
| 69 | + steps: |
| 70 | + - uses: actions/checkout@v4 |
| 71 | + - uses: dbt-labs/terraform-dbtcloud-as-yaml/validate@v1 |
| 72 | + with: |
| 73 | + file: dbt-config.yml |
| 74 | +
|
| 75 | + plan: |
| 76 | + name: Terraform Plan |
| 77 | + runs-on: ubuntu-latest |
| 78 | + needs: validate # only runs when YAML is valid |
| 79 | + env: |
| 80 | + TF_VAR_dbt_account_id: ${{ secrets.DBT_ACCOUNT_ID }} |
| 81 | + TF_VAR_dbt_token: ${{ secrets.DBT_TOKEN }} |
| 82 | + TF_VAR_dbt_host_url: "https://cloud.getdbt.com" |
| 83 | + TF_VAR_environment_credentials: ${{ secrets.ENVIRONMENT_CREDENTIALS }} |
| 84 | + steps: |
| 85 | + - uses: actions/checkout@v4 |
| 86 | + - uses: hashicorp/setup-terraform@v3 |
| 87 | + - run: terraform init |
| 88 | + - run: terraform plan -no-color |
| 89 | +``` |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## Example Error Output |
| 94 | + |
| 95 | +When a YAML file fails validation the action prints a structured report and exits with code `1`: |
| 96 | + |
| 97 | +``` |
| 98 | +Validating 'dbt-config.yml' against dbt Cloud YAML schema v1... |
| 99 | +Schema validation errors were encountered. |
| 100 | + dbt-config.yml::$: 'version' is a required property |
| 101 | + dbt-config.yml::$.account: 'host_url' is a required property |
| 102 | + dbt-config.yml::$.projects[0].environments[0].credential: 'token_name' is a required property |
| 103 | +Error: Process completed with exit code 1. |
| 104 | +``` |
| 105 | + |
| 106 | +Each line identifies the exact JSON path where the violation occurred, making it straightforward to find and fix the issue. |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +## Versioning |
| 111 | + |
| 112 | +Pin the action to a release tag or commit SHA to avoid unexpected breaking changes: |
| 113 | + |
| 114 | +```yaml |
| 115 | +# Pin to a release tag (recommended) |
| 116 | +- uses: dbt-labs/terraform-dbtcloud-as-yaml/validate@v1 |
| 117 | +
|
| 118 | +# Pin to a specific commit SHA for maximum reproducibility |
| 119 | +- uses: dbt-labs/terraform-dbtcloud-as-yaml/validate@2bb4e9e |
| 120 | +``` |
| 121 | + |
| 122 | +Avoid `@main` in production workflows — it tracks the development branch and may change at any time. |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +## Next Steps |
| 127 | + |
| 128 | +<div class="grid cards" markdown> |
| 129 | + |
| 130 | +- :material-pipe:{ .lg .middle } **CI/CD Integration** |
| 131 | + |
| 132 | + --- |
| 133 | + |
| 134 | + Full CI and CD pipeline examples for GitHub Actions, GitLab, and Azure DevOps |
| 135 | + |
| 136 | + [:octicons-arrow-right-24: CI/CD Guide](cicd.md) |
| 137 | + |
| 138 | +- :material-file-code:{ .lg .middle } **YAML Schema Reference** |
| 139 | + |
| 140 | + --- |
| 141 | + |
| 142 | + Full field reference for `dbt-config.yml` |
| 143 | + |
| 144 | + [:octicons-arrow-right-24: YAML Schema](../configuration/yaml-schema.md) |
| 145 | + |
| 146 | +- :material-security:{ .lg .middle } **Best Practices** |
| 147 | + |
| 148 | + --- |
| 149 | + |
| 150 | + Secure and reliable deployments |
| 151 | + |
| 152 | + [:octicons-arrow-right-24: Best Practices](best-practices.md) |
| 153 | + |
| 154 | +</div> |
0 commit comments