fix: write Terragrunt plan artifacts to the run's unique temp dir#205
Merged
patrickchugh merged 1 commit intoJun 28, 2026
Merged
Conversation
tg_initplan built tg_tfplan.bin, tg_tfplan.json and tg_tfgraph.dot under tempfile.gettempdir(), the shared temp root (usually /tmp), at fixed names. Two terravision runs against Terragrunt sources at once then write to the same files and overwrite each other's plan and graph. Write them into tfwrapper.temp_dir.name instead, the per-process TemporaryDirectory terravision already uses for Terraform artifacts, so each run keeps its files in its own directory. tempfile is no longer used in this module, so drop the import. tg_run_all_plan (multi-module) calls tg_initplan per child module, so it inherits the fix. This is the Terragrunt counterpart of the same fix in tf_initplan.
d7bafda to
2e7ab34
Compare
Owner
|
@jcoffi Thanks for the PR. |
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 #204
Sibling of #202 / #203, which fix the same temp-path collision for plain Terraform in
tf_initplan. This PR applies the same fix to the Terragrunt path.Type of Change
What this changes
tg_initplan()inmodules/tgwrapper.pywrote its plan artifacts (tg_tfplan.bin,tg_tfplan.json,tg_tfgraph.dot) intotempfile.gettempdir(), the shared temp root (usually/tmp), under fixed names. Twoterravisionruns against Terragrunt sources at once then write to the same files and overwrite each other's plan and graph.tg_run_all_plan()(multi-module) runstg_initplan()once per child module, so it shares the same paths.The fix writes the artifacts into
tfwrapper.temp_dir.name, the per-processTemporaryDirectoryterravision already uses for Terraform artifacts.tempfileis no longer referenced in the module, so the import is removed.Why this is safe
tfwrapper.temp_diris the module-levelTemporaryDirectorycreated at import, already used for Terraform plan artifacts and asTF_DATA_DIR. tgwrapper already depends on tfwrapper for_write_override,convert_dot_to_json, andtf_makegraph, so this adds no new coupling.tg_prefix, so they do not clash with the Terraform artifacts in the same directory._run_terragrunt_plan()and_decode_tg_plan()receive the same path variables, so they follow the new location automatically.Testing
python -m black --check modules/tgwrapper.pypasses.python -m py_compile modules/tgwrapper.pypasses.tests/test_tgwrapper.pyare marked@pytest.mark.slowand exercisetg_initplan/tg_run_all_planend to end. They assert on the returned tfdata (resource types, codepath, override cleanup), not on the temp-file location, so this change does not affect them. I could not run the slow suite in my environment (no terragrunt binary available).A note on scope
This is intentionally a single focused change for the Terragrunt path, paired with the Terraform fix in #203. Between them they cover both
tf_initplanandtg_initplan.Checklist
All Submissions:
AI Assistance Declaration
tg_initplan, applied the fix, removed the now-unusedtempfileimport, and wrote this PR.Checklist for Changes to Core Features: