Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(terraform_docs): Suppress "terraform command not found" error message in case binary does not exist #693

Merged
merged 4 commits into from
Aug 1, 2024

Conversation

ponceps
Copy link
Contributor

@ponceps ponceps commented Jul 31, 2024

Put an x into the box if that apply:

  • This PR introduces breaking change.
  • This PR fixes a bug.
  • This PR adds new functionality.
  • This PR enhances existing functionality.

Description of your changes

If you are using OpenTofu and don't have Terraform binary installed, terraform_docs hook will display a command not found error. The error line checks if Terraform release is 0.12, so it's possible suppress this error message if Terraform binary doesn't exist.

image

How can we test changes

Below are the steps to reproduce the error.

  1. Install OpenTofu
  2. Uninstall Terraform (or remove it from PATH)
  3. Make any changes to variables.tf or outputs.tf
  4. Run pre-commit -a
image

@yermulnik
Copy link
Collaborator

@MaxymVlasov Are you ok with the change?

Copy link
Collaborator

@MaxymVlasov MaxymVlasov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks legit

@MaxymVlasov MaxymVlasov changed the title fix: Hook terraform_docs should suppress command not found error message in case terraform binary does not exist fix(terraform_docs): Suppress "command not found" error message in case terraform binary does not exist Aug 1, 2024
@MaxymVlasov
Copy link
Collaborator

MaxymVlasov commented Aug 1, 2024

just lmc that it will not fail silently
UPD. It works without opentofu too
UPD2. It fail to hacky way for old TF

@MaxymVlasov MaxymVlasov self-requested a review August 1, 2024 17:02
hooks/terraform_docs.sh Outdated Show resolved Hide resolved
@yermulnik
Copy link
Collaborator

yermulnik commented Aug 1, 2024

just lmc that it will not fail silently

What's lmc? 🤔
If it fails, then we suppress failure (|| true) and var is left empty.
The change simply suppresses error output.

ps: it might make sense to wrap the hack_terraform_docs=$(terraform version 2> /dev/null | sed -n 1p | grep -c 0.12) || true command in conditional like this:

local hack_terraform_docs=0
if [[ $(\command -V terraform 2> /dev/null) ]]; then
  hack_terraform_docs=$(terraform version | sed -n 1p | grep -c 0.12) || true
fi

WDTY?

hooks/terraform_docs.sh Outdated Show resolved Hide resolved
hooks/terraform_docs.sh Outdated Show resolved Hide resolved
@MaxymVlasov MaxymVlasov changed the title fix(terraform_docs): Suppress "command not found" error message in case terraform binary does not exist fix(terraform_docs): Suppress "terraform command not found" error message in case binary does not exist Aug 1, 2024
@MaxymVlasov MaxymVlasov merged commit 6ff3572 into antonbabenko:master Aug 1, 2024
6 checks passed
antonbabenko pushed a commit that referenced this pull request Aug 1, 2024
## [1.92.1](v1.92.0...v1.92.1) (2024-08-01)

### Bug Fixes

* **`terraform_docs`:** Suppress "terraform command not found" error message in case binary does not exist ([#693](#693)) ([6ff3572](6ff3572))
@antonbabenko
Copy link
Owner

This PR is included in version 1.92.1 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants