Add Exception handling when Terraform not on Path #127
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.
I spent a couple hours helping a colleague debug why his
python_terraform
code was unexpectedly throwingFileNotFoundError
s. It finally boiled down to the terraform binary not being on Path. Windows didn't offer any helpful hints to which file in the error messages. I also tested it on Ubuntu which would at least provide that "terraform" was the file. This is a result ofsubprocess.Popen
not knowing what to do with "terraform" and trying to open something by that name. When terraform is not on Path and the binary path not provided, it will always die on the call top = subprocess.Popen(...)
. I added exception handling to better inform users, especially on Windows, what the issue likely is when not providing a path to the binary. I tried to work my way best around still getting theTerraformCommandError
to logs while giving context.