Skip to content

Commit fd035e3

Browse files
authored
Fix verbose OpenTofu error tracebacks (#3149)
1 parent f35afc7 commit fd035e3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/_nebari/provider/opentofu.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,16 @@ def download_opentofu_binary(version=constants.OPENTOFU_VERSION):
112112
return filename_path
113113

114114

115-
def run_tofu_subprocess(processargs, **kwargs):
115+
def run_tofu_subprocess(processargs, exit_on_error=True, **kwargs):
116116
tofu_path = download_opentofu_binary()
117117
logger.info(f" tofu at {tofu_path}")
118118
exit_code, output = run_subprocess_cmd([tofu_path] + processargs, **kwargs)
119119
if exit_code != 0:
120-
raise OpenTofuException("OpenTofu returned an error")
120+
if exit_on_error:
121+
logger.error("Error: OpenTofu command failed")
122+
sys.exit(1)
123+
else:
124+
raise OpenTofuException("OpenTofu returned an error")
121125
return output
122126

123127

@@ -174,6 +178,7 @@ def tfimport(addr, id, directory=None, var_files=None, exist_ok=False):
174178
try:
175179
run_tofu_subprocess(
176180
command,
181+
exit_on_error=False,
177182
cwd=directory,
178183
prefix="tofu",
179184
strip_errors=True,
@@ -196,6 +201,7 @@ def show(directory=None, tofu_init: bool = True) -> dict:
196201
output = json.loads(
197202
run_tofu_subprocess(
198203
command,
204+
exit_on_error=False,
199205
cwd=directory,
200206
prefix="tofu",
201207
strip_errors=True,

0 commit comments

Comments
 (0)