Skip to content

ci(terraform): run tofu validate on tf/ in the CI gate #6074

Not planned

Description

@devops-cli-service

Split from #5074.

Problem: no check validates tf/. The devops ci gate holds 26 rows and none runs tofu validate (src/devops_cli/commands/ci.py:120), as the archived proposal of #5065 records. Issue #5074 moves tf/azure to azurerm ~> 5.13 and runs tofu init -backend=false && tofu validate by hand, but nothing fails when a later edit breaks the provider schema. OpenTofu 1.13.9 is already in the devcontainer image (.devcontainer/Dockerfile:206) and the static CI job installs it (.github/workflows/ci.yml:80), so no image change is needed. Why deferred: the gate is a new row of devops ci (code in src/devops_cli/commands/ci.py) or a new workflow step, and it needs a committed tf/azure/.terraform.lock.hcl plus a time budget inside the static job's 6 minutes (.github/workflows/ci.yml:51). Issue #5074 keeps the pin, the guide edits and the offline tests. Acceptance criteria: - tf/azure/.terraform.lock.hcl pins hashicorp/azurerm 5.13 with the checksums of the provider builds. - A check runs tofu init -backend=false and then tofu validate in tf/azure and fails when the configuration does not match the provider schema. - The check needs no Azure credentials. - The static job stays under its 6-minute timeout. tofu plan against a real subscription stays out of scope: it needs a test subscription that a person provides.

Proposed design

Problem statement

tf/azure has no CI check. The devops ci registry holds no OpenTofu row, so an edit that breaks the provider schema passes every gate. Add a tofu row that runs tofu init -backend=false and tofu validate in tf/azure, commit the azurerm 5.13 lock file, and fail when init changes the lock file. The row needs no Azure credential and stays inside the static job's 6-minute timeout. It waits on #5074 for the azurerm 5.13 pin.

Acceptance criteria

Requirement: The tofu row joins the gate registry

The devops ci check registry SHALL hold a tofu row whose command runs the main of tests/gate/tofu_validate.py, and CHECK_ROW_NAMES SHALL name tofu in registry order.

Scenario: The row is in the registry

  • WHEN the row registry test reads CHECK_ROW_NAMES and the tofu check spec
  • THEN it finds tofu in CHECK_ROW_NAMES and the command uv run python -c with CONST_GATE_ROW_SCRIPT for tofu_validate

Requirement: The row runs init and validate in tf/azure

The tofu row MUST run tofu init -backend=false and then tofu validate, each with tf/azure as the working directory, and MUST fail when either command exits non-zero.

Scenario: A fake tofu records the two commands

  • WHEN the gate module runs with a fake tofu on PATH that records its argv and working directory and exits 0
  • THEN the module returns 0 and the fake holds ['tofu', 'init', '-backend=false'] and ['tofu', 'validate'], both run in tf/azure

Requirement: The row fails when validate rejects the configuration

The tofu row MUST return a non-zero exit code when tofu validate exits non-zero.

Scenario: A fake tofu validate fails

  • WHEN the gate module runs with a fake tofu whose validate exits 1
  • THEN the module returns 1 and prints the failed tofu validate command

Requirement: The row refuses a missing lock file

The tofu row SHALL fail with a finding that names tf/azure/.terraform.lock.hcl when that file is absent before tofu init.

Scenario: The lock file is absent

  • WHEN the gate module runs in a tree with no tf/azure/.terraform.lock.hcl
  • THEN the module returns 1 and prints tf/azure/.terraform.lock.hcl is missing: run tofu init and commit the file

Requirement: The row refuses a changed lock file

The tofu row SHALL fail with a finding that names tf/azure/.terraform.lock.hcl when its bytes change during tofu init.

Scenario: init rewrites the lock file

  • WHEN the fake tofu init appends a checksum to tf/azure/.terraform.lock.hcl and exits 0
  • THEN the module returns 1 and prints tf/azure/.terraform.lock.hcl changed during tofu init: commit the file that tofu wrote

Requirement: The row needs no Azure credential

The tofu row SHALL pass on a host that holds no Azure credential, because tofu init -backend=false reads no backend and tofu validate makes no cloud API call.

Scenario: The static job runs the row without a credential

  • WHEN uv run devops ci --check --only tofu runs in the Static Analysis job
  • THEN the row exits 0 and its output names no ARM_* or AZURE_* variable

Requirement: The row fits the static job

The tofu row SHALL set timeout_seconds to 120, under the static job's 6-minute timeout.

Scenario: The row bound is 120 seconds

  • WHEN the row registry test reads the timeout_seconds of the tofu check spec
  • THEN the test asserts the value is 120

Requirement: The lock file pins azurerm 5.13

tf/azure/.terraform.lock.hcl MUST be committed with the checksums of hashicorp/azurerm 5.13 for linux_amd64.

Scenario: The gate row keeps the committed lock file

  • WHEN uv run devops ci --check --only tofu runs on the ubuntu-26.04 runner
  • THEN the row passes with tf/azure/.terraform.lock.hcl unchanged

Requirement: The static job caches the provider directory

The Static Analysis job SHALL cache the OpenTofu provider directory under a key of tf/azure/.terraform.lock.hcl and SHALL give that directory to the gate step as TF_PLUGIN_CACHE_DIR.

Scenario: The edited workflow passes its validators

  • WHEN uv run devops ci --check --only actionlint,zizmor runs
  • THEN both rows pass

Requirement: The change records the row in the gate spec

The change SHALL add the tofu row's requirement to the ci-gate-rows specification.

Scenario: The OpenSpec check passes

  • WHEN uv run devops ci --check --only openspec runs
  • THEN the row passes with the change's spec delta on ci-gate-rows

Existing Tool Considered

No alternatives check has run. OpenTofu CLI 1.13.9 (MPL-2.0) is the open, maintained tool that covers the need. It is already in the devcontainer at .devcontainer/Dockerfile:206, and the static job installs it at .github/workflows/ci.yml:80. It runs tofu init -backend=false and tofu validate with no Azure credential. It lacks a check against a real subscription: tofu plan needs a test subscription and credentials that a person provides, so that part stays out of scope. The project's devops tf init lacks a -backend=false option and a lock-file guard, so the gate row uses a tests/gate module.

Key questions

  • Which gate runs the tofu check?: Add a tofu row to CHECK_ROW_NAMES and the check registry. The existing Static Analysis job runs every row and already installs OpenTofu. The row command uses _python_check_cmd('tofu_validate'). (best practice) [sources: src/devops_cli/commands/ci.py:135, src/devops_cli/commands/ci.py:931, .github/workflows/ci.yml:80, openspec/specs/ci-gate-rows/spec.md]
    • Chosen: New devops ci row. The gate dispatches rows from one registry, and the static job already runs every row and installs OpenTofu.
    • Rejected: New workflow step. It splits the check from the local gate, repeats the OpenTofu setup, and leaves devops ci unable to run the check.
  • How does one row run two commands in tf/azure?: Use a tests/gate/tofu_validate.py module that the row starts with _python_check_cmd('tofu_validate'). The module owns the working directory, runs tofu init -backend=false and then tofu validate in tf/azure, and passes TF_PLUGIN_CACHE_DIR to both commands. (best practice) [sources: src/devops_cli/commands/ci.py:205, src/devops_cli/commands/ci.py:931, src/devops_cli/config/constants.py:2605, openspec/specs/ci-gate-rows/spec.md]
    • Chosen: A tests/gate module. It fits the row pattern, owns the working directory and the environment, and needs no product command change.
    • Rejected: Two devops tf commands via also_cmds. devops tf init has no -backend=false option and no lock-file guard, and also_cmds run in the repository root, not in tf/azure.
    • Rejected: Extend devops tf init and devops tf validate. It grows the product CLI, its docs and the MCP tool snapshots for a CI-only need.
  • How does the row enforce a committed provider lock file?: The module hashes tf/azure/.terraform.lock.hcl before tofu init -backend=false and after. It fails with a finding that names the path when the file is absent or its bytes change. A valid committed lock file is left untouched by init. (best practice) [sources: tf/azure/versions.tf, src/devops_cli/commands/tf.py]
    • Chosen: Compare the lock file before and after init. It uses the file the project already names as the lock file, and it fails on a missing, stale or platform-incomplete file.
    • Rejected: tofu init -lockfile=readonly. No source in this repository or the issue documents that flag, so the row must not depend on it.
    • Rejected: git diff after init. It couples the row to git state, and an unrelated worktree change makes the result unclear.
  • Does tofu validate need Azure credentials?: No. The project classes devops tf validate as no-external-request: it runs tofu validate in the directory, and the provider schema check makes no Azure API call. -backend=false keeps init from reading a backend configuration. The Static Analysis job sets no Azure credential. [sources: src/devops_cli/commands/tf.py]
  • Which provider platforms does the lock file need?: linux_amd64, the platform of the ubuntu-26.04 runner. The gate runs on that runner only. An arm64 devcontainer can add its own checksums later if a local run shows a dirty lock file. (best practice) [sources: .github/workflows/ci.yml:51, tf/azure/versions.tf]
    • Chosen: Runner platform only. The gate runs on linux_amd64, so the committed lock file covers the check.
    • Rejected: Runner and devcontainer platforms. It adds arm64 checksums that no CI check runs and no acceptance criterion proves.
    • Rejected: Every developer platform. It adds checksums for platforms that neither the gate nor the devcontainer runs.
  • How does the static job stay under its time limit?: The row sets timeout_seconds=120, under the static job's 6-minute timeout. The static job also caches the OpenTofu provider directory with actions/cache at the pinned digest, keyed on tf/azure/.terraform.lock.hcl, and gives that directory to the gate step as TF_PLUGIN_CACHE_DIR. (best practice) [sources: .github/workflows/ci.yml:51, .github/workflows/ci.yml:80, .github/actions/setup-toolchain/action.yml:53, src/devops_cli/commands/ci.py:205, src/devops_cli/ai/knowledge_base/devops_cli/tasks/infrastructure_provisioning.md]
    • Chosen: Row bound plus provider cache. The bound fails a hung run before the job limit, and the cache keeps the provider download out of the critical path.
    • Rejected: No cache. The provider download repeats on every run of a job that has 6 minutes for all rows.
    • Rejected: No row bound. A hung download then fails as a job timeout that names no row.
    • Rejected: Separate job. It repeats checkout, the toolchain and the OpenTofu setup, and the job limit is the 6 minutes the issue already constrains.
  • What does this issue wait on?: build(terraform): move the azurerm provider to 5.x #5074 moves tf/azure to azurerm ~> 5.13 and keeps the pin. This issue commits the lock file after that. tf/azure/versions.tf still holds version = "~> 3.100" at this commit. [sources: tf/azure/versions.tf]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#5074

Activity

  1. added
    type/infra
    scope/terraform
    source/agent
    status/new
    on Nov 16, 2026
  2. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    ContributorAuthor
  3. added
    value/medium
    effort/low
    priority/p2-medium
    on Nov 16, 2026
  4. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    ContributorAuthor

    Refine cannot set this item to Ready at 4ddf77e while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

    The next refine round also looks at the item again when a commit on the default branch changes one of these files: tf/azure/versions.tf.

  5. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    ContributorAuthor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

  6. dan-petty commented on Nov 26, 2026

    @dan-petty
    Owner

    Closed: tf/ moved to dan-petty/infra, and the check exists there.

    The OpenTofu job of the infra CI runs tofu init -backend=false and tofu validate in each folder of tf/examples/, with committed lock files. This repository holds no tf/ code to validate.

  7. removed
    status/new
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/terraformsource/agenttype/infravalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions