Skip to content

feat(opentofu): add init-backend input for credential-free lint jobs - #72

Merged
nkg merged 1 commit into
mainfrom
feat/opentofu-init-backend
Aug 30, 2026
Merged

feat(opentofu): add init-backend input for credential-free lint jobs#72
nkg merged 1 commit into
mainfrom
feat/opentofu-init-backend

Conversation

@nkg

@nkg nkg commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Summary

A fmt/validate-only job on a configuration that has a backend block cannot run tofu init bare — the S3 backend resolves credentials during init, so the job dies with No valid credential sources found before validate is ever reached. The configuration is fine; the job simply has no business holding state-write credentials in order to lint HCL.

init-backend: false passes -backend=false, which initialises providers and modules and skips the backend entirely.

Surfaced by HordiaLabs/platform moving its OpenTofu state to Cloudflare R2 (HordiaLabs/platform#26): three stacks that had been linting green on local state went red the moment the backend blocks landed. No Linear issue.

Changes

  • .github/workflows/opentofu.yml
    • New init-backend boolean input, default true.
    • New guard step: init-backend: false together with run-plan: true is a contradiction (plan needs state), so it now fails fast with an explicit ::error:: rather than surfacing as a confusing failure two steps later.
  • CHANGELOG.md — entry under [Unreleased].
  • examples/README.md — lint-only example alongside the existing OpenTofu one.

No new dependencies.

Test Plan

  • actionlint clean across the repo
  • yamllint clean on the changed workflow
  • Reproduced the failure locally: tofu init against an R2 backend "s3" with no credentials → No valid credential sources found
  • Verified the fix locally: tofu init -backend=false && tofu validateSuccess! The configuration is valid. on all three platform stacks
  • Consumer run green on HordiaLabs/platform once this is released

Notes for Reviewers

Default is true, so every existing caller produces a byte-identical command line — the new flag is only appended when explicitly set to false. That is the main thing to check.

Needs a v3.2.0 tag after merge: HordiaLabs/platform#26 pins @v3 and passes this input, so it stays red until the floating v3 tag moves.

I did not backport to the v2 line. The release process is tag-from-main, v3 is the current line, and this is a new feature rather than a fix — but say the word if v2.18.0 is wanted too, since most consumers are still on @v2.

🤖 Generated with Claude Code

https://claude.ai/code/session_017EDkXRcCrVDfu2e8V9Yy52

A fmt/validate-only job on a configuration that has a `backend` block
cannot run `tofu init` bare: the S3 backend resolves credentials during
init, so the job dies with "No valid credential sources found" before
`validate` is ever reached. The configuration is fine; the job simply has
no business holding state-write credentials to lint HCL.

`init-backend: false` passes `-backend=false`, which initialises providers
and modules and skips the backend entirely. Default stays `true`, so every
existing caller produces a byte-identical command line.

Setting it alongside `run-plan: true` is a contradiction — plan needs
state — so that combination now fails fast with an explicit error rather
than surfacing as a confusing failure two steps later.

Prompted by hordialabs/platform moving its OpenTofu state to Cloudflare R2:
three stacks that had been linting green on local state went red the moment
the backend blocks landed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017EDkXRcCrVDfu2e8V9Yy52
@nkg
nkg merged commit 3d689d7 into main Aug 30, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant