Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions python_terraform/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,28 @@ def cmd(
if self.is_env_vars_included:
environ_vars = os.environ.copy()

p = subprocess.Popen(
cmds, stdout=stdout, stderr=stderr, cwd=working_folder, env=environ_vars
)
try:
p = subprocess.Popen(
cmds, stdout=stdout, stderr=stderr, cwd=working_folder, env=environ_vars
)
except FileNotFoundError as fnfe_exc:
# if no other path to the terraform binary was provided
if self.terraform_bin_path == "terraform":
msg = (
"The 'terraform' command failed to invoke. Ensure the terraform " \
"binary is on Path or provide the correct path to the binary."
)
try:
# keep the command error to get to logs
raise TerraformCommandError(
1, " ".join(cmds), out="", err=type(fnfe_exc).__name__
) from fnfe_exc
except TerraformCommandError as tfce_exc:
# add context for why 'terraform' invoke failed
raise RuntimeError(msg) from tfce_exc

else:
raise TerraformCommandError(1, " ".join(cmds), out="", err=repr(fnfe_exc)) from fnfe_exc

if not synchronous:
return None, None, None
Expand Down