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

Add hook for autoformat of terraform code snippets embedded in the docs #256

Open
antonbabenko opened this issue Oct 22, 2021 · 2 comments
Labels
estimate/2days Need 2 work days to be done feature New feature or request good first issue Good for newcomers hook/terrafmt Bash hook

Comments

@antonbabenko
Copy link
Owner

There is a utility called terrafmt that can be used to check and fix the formating of Terraform snippets embedded into usage sections in README.

How could pre-commit-terraform help solve your problem?

It would be great to have native support as a pre-commit hook.

@antonbabenko antonbabenko added the feature New feature or request label Oct 22, 2021
@MaxymVlasov MaxymVlasov added the estimate/2days Need 2 work days to be done label Oct 25, 2021
@MaxymVlasov MaxymVlasov added the good first issue Good for newcomers label Oct 29, 2021
@rahulmlokurte
Copy link

@MaxymVlasov @antonbabenko: Can I pick the terrafmt hook? I have tried it in my system. Looks like, terrafmt does not extract terraform files and does not do inline code formatting from the README.md file if, we start the Three backquotes after 4 spaces in the README.md file. It only works, if we start the Three backquotes at column 0.

Ex:

  1. Works:

image

terrafmt blocks README.md

####### B1 @ #587
resource "aws_lambda_function" "pass" {
  function_name = "test-env"
  role          = ""
  runtime       = "python3.8"

  environment {
    variables = {
      AWS_DEFAULT_REGION = "us-west-2"
    }
  }
}
  1. Does not work

image

terrafmt blocks README.md

The README.md in the repository has all the inline code starting at 4 spaces. For ex: Hooks usage notes and examples , apart from checkov, all other sections defines the inline code starting at 4 spaces.

@antonbabenko
Copy link
Owner Author

Sounds like this is the problem in terrafmt because markdown format allows having an offset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
estimate/2days Need 2 work days to be done feature New feature or request good first issue Good for newcomers hook/terrafmt Bash hook
Projects
None yet
Development

No branches or pull requests

3 participants