fix: write Terraform plan artifacts to the run's unique temp dir#203
Merged
patrickchugh merged 1 commit intoJun 28, 2026
Merged
Conversation
This was referenced Jun 26, 2026
tf_initplan built tfplan.bin, tfplan.json and tfgraph.dot under os.path.dirname(temp_dir.name). temp_dir is the per-process TemporaryDirectory, so taking its parent collapses the path back to the shared temp root (usually /tmp) and the three files land at fixed, shared paths. Two terravision runs at once then write to the same /tmp/tfplan.bin (and .json/.dot) and overwrite each other's plan and graph mid-run. Use temp_dir.name directly so each run keeps its artifacts in its own directory. temp_dir.name is already stored as terraform_init_dir and _decode_plan reads the same local paths, so nothing else changes.
a6fdf4c to
d0cf4bf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #202
Type of Change
What this changes
tf_initplan()inmodules/tfwrapper.pywrote its plan artifacts (tfplan.bin,tfplan.json,tfgraph.dot) intoos.path.dirname(temp_dir.name).temp_diris the per-processtempfile.TemporaryDirectory, so taking its parent collapses the path back to the shared temp root (usually/tmp). The three artifacts therefore landed at fixed, shared paths.Run two
terravisionprocesses at the same time and they write to the same/tmp/tfplan.bin(and.json/.dot), so they overwrite each other's plan and graph partway through a run. In practice this shows up as corrupted or mismatched diagrams when terravision runs concurrently, for example across parallel CI jobs sharing one runner.The fix uses
temp_dir.namedirectly, so each run keeps its artifacts inside its own unique directory.Why this is safe
temp_dir.nameis already the directory terravision stores astfdata["terraform_init_dir"](same file, line 371), so the plan artifacts now sit alongside the init data they belong with._decode_plan()reads the same three local path variables, so it follows the new location automatically.read_tfsource()locates modules viaterraform_init_dir, not these artifact paths, so module resolution is unaffected.Testing
python -m black --check modules/tfwrapper.pypasses.python -m py_compile modules/tfwrapper.pypasses.tf_initplan(), where the artifact paths are local variables built inline between realterraformsubprocess calls, so there is no clean seam to assert on without a small refactor. This PR is kept to the minimal one-line fix on purpose. I am happy to follow up with a refactor that extracts the path construction into a helper plus a regression test if you would prefer that.A sibling bug left untouched
modules/tgwrapper.pyhas the same fixed-path pattern for Terragrunt (/tmp/tg_tfplan.binand friends, around line 682). I left it out to keep this PR to a single change, but it is worth a separate fix.Checklist
All Submissions:
AI Assistance Declaration
tf_initplan/_decode_plan/read_tfsource, made the one-line fix, and wrote this PR.Checklist for Changes to Core Features: