Skip to content

fix(export): let the consumer own versions.tf - #177

Merged
2000game merged 1 commit into
mainfrom
fix/export-tf-own-versions
Sep 17, 2026
Merged

2000game merged 1 commit into
mainfrom
fix/export-tf-own-versions

Conversation

@2000game

Copy link
Copy Markdown
Member

ct export tf owned versions.tf unconditionally — written every run, pruned when unwritten. That made the file impossible to own.

It is the one generated file a consumer has a real reason to own:

  • A provider version constraint lives inside required_providers and has nowhere else to go, so pinning was impossible. src/export/provider.ts already said "pinning belongs in the user's repo" — the code contradicted it.
  • A consumer who also keeps a backend block there loses it silently on the next export, and the next tofu init falls back to local state while the real state sits in the configured backend. Reproduced against ct-structure's tier-0 stack.

Fix

--no-versions opts out. The file is then neither written nor pruned — dropping it from the owned set is the important half, because pruning would delete the consumer's file, which is worse than overwriting it: nothing would hint at why it vanished.

Default behaviour is unchanged, so a first-time migration still gets a runnable root module.

Verification

Reproduced and fixed end to end against real prod state:

run backend block version pin
export tf (default) gone gone
export tf --no-versions survives survives

tofu validate passes on the result. 4 new tests; full suite 1131 passing.

`ct export tf` owned versions.tf unconditionally — written every run,
and pruned when unwritten. That made the file impossible to own, which
matters because it is the one generated file a consumer has a real
reason to own:

- A provider VERSION CONSTRAINT lives inside required_providers and has
  nowhere else to go, so pinning was impossible. provider.ts already
  said pinning belongs in the consumer's repo; the code contradicted it.
- A consumer who also keeps a backend block there loses it SILENTLY on
  the next export, and `tofu init` then falls back to local state while
  the real state sits in the configured backend. Reproduced against
  ct-structure's stack.

`--no-versions` opts out. The file is then neither written nor pruned —
dropping it from the owned set matters, because pruning would delete the
consumer's file outright, which is worse than overwriting it: nothing
would hint at why it vanished.

Default is unchanged, so a first-time migration still gets a runnable
root module.
@2000game
2000game merged commit 22b21f0 into main Sep 17, 2026
3 checks passed
@2000game
2000game deleted the fix/export-tf-own-versions branch September 17, 2026 15:20
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