From 2e7ab348fc915ca670d497899429b283d454a3d2 Mon Sep 17 00:00:00 2001 From: Justin Coffi <21188264+jcoffi@users.noreply.github.com> Date: Fri, 26 Jun 2026 13:47:35 -0700 Subject: [PATCH] fix: write Terragrunt plan artifacts to the run's unique temp dir 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. --- modules/tgwrapper.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/tgwrapper.py b/modules/tgwrapper.py index da1df1b..4bb4a15 100644 --- a/modules/tgwrapper.py +++ b/modules/tgwrapper.py @@ -8,7 +8,6 @@ import os import re import subprocess -import tempfile from pathlib import Path from typing import Any, Dict, List, Tuple @@ -679,9 +678,11 @@ def tg_initplan( check_terragrunt_version() codepath, override_files = _prepare_tg_source(source) - tfplan_path = os.path.join(tempfile.gettempdir(), "tg_tfplan.bin") - tfplan_json_path = os.path.join(tempfile.gettempdir(), "tg_tfplan.json") - tfgraph_path = os.path.join(tempfile.gettempdir(), "tg_tfgraph.dot") + # Write plan artifacts into the per-process temp dir (not the shared + # /tmp root) so concurrent terravision runs don't clobber each other. + tfplan_path = os.path.join(tfwrapper.temp_dir.name, "tg_tfplan.bin") + tfplan_json_path = os.path.join(tfwrapper.temp_dir.name, "tg_tfplan.json") + tfgraph_path = os.path.join(tfwrapper.temp_dir.name, "tg_tfgraph.dot") try: cache_dir = _run_terragrunt_init(codepath, debug)