Giter VIP home page Giter VIP logo

Comments (18)

antonbabenko avatar antonbabenko commented on September 19, 2024 2

@thenom pre-commit autoupdate updated hooks to the very latest where terraform_docs has native support for Terraform 0.12.

Thanks for mentioning SKIP=...!

from pre-commit-terraform.

antonbabenko avatar antonbabenko commented on September 19, 2024

Please try v1.16.0.

If the problem persists please provide the failing snippet of the code you are trying to process.

from pre-commit-terraform.

thenom avatar thenom commented on September 19, 2024

Ok, all autoupdated and still getting the same problems:

$ pre-commit run terraform_docs -a
Terraform docs...........................................................Failed
hookid: terraform_docs

2019/06/19 19:27:28 At 62:1: expected: IDENT | STRING | ASSIGN | LBRACE got: RBRACE

and

pre-commit run terraform_docs -a
Terraform docs...........................................................Failed
hookid: terraform_docs

2019/06/19 19:23:01 At 13:15: nested object expected: LBRACE got: ASSIGN

It is always 1 of the 2 above but as a test i created a new local tf repo with:

$ cat README.md
Test documentation

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
$ cat variables.tf
variable "test_var" {
  description = "This is a test variable"
  default     = ""
  type        = string
}
$ cat .pre-commit-config.yaml
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
  rev: v1.16.0
  hooks:
  - id: terraform_fmt
  - id: terraform_docs

and forced ran the pre-commit on it which worked:

$ pre-commit run -a
Terraform fmt............................................................Failed
hookid: terraform_fmt

Files were modified by this hook. Additional output:

variables.tf

Terraform docs...........................................................Failed
hookid: terraform_docs

Files were modified by this hook.
$ cat README.md
Test documentation

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| test\_var | This is a test variable | string | `""` | no |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

I am afraid my TF modules are quite large and i am force running this to test it as i have not changed anything that would trigger it hence doing the minimal test. I have tried it on 4 of our repos so far and all have failed with one of the 2 errors.

As a side test though i cleaned out all output in a few of the README's (between the block identifier hooks) and re-ran and still got the same error on each.

Just a note though, these are all v0.11 TF code that i am currently in the process of converting to 0.12, not sure if this is relevant but thought it might be worth mentioning as the test setup i ran was fine.

Thanks again

from pre-commit-terraform.

thenom avatar thenom commented on September 19, 2024

Just an additional note, 1.16.0 works fine on pure TF 0.11 files.

from pre-commit-terraform.

antonbabenko avatar antonbabenko commented on September 19, 2024

I tried to reproduce this several times with Terraform 0.12 and latest pre-commit-terraform (v1.16.0), but can't reproduce it.

When Terraform 0.11 is used the terraform_docs hook uses previous behavior (no awk script of other magic is necessary) and it works fine.

Let's keep it open for some time in case someone experiences a similar issue as you are describing and can provide failing code.

from pre-commit-terraform.

gstewart avatar gstewart commented on September 19, 2024

Try with a single file (variables.tf for me) with something like this:

variable "test" {
  type        = "string"
  description = "testing"
}

With quotes around the string, you end up with two sets of quotes around it after the awk script runs (ex. ""string""). This is what terraform docs seems to fail on. If you remove the quotes from around it, everything runs ok.

This only seems to happen when the type line comes first and then another line like description comes after. If the type line comes on the second line, or is the only line between the brackets, you'll get a different exception.

from pre-commit-terraform.

thenom avatar thenom commented on September 19, 2024

Correct @gstewart,

I changed my test setup variables.tf to:

variable "test_var" {
  type        = "string"
  description = "This is a test variable"
  default     = ""
}

and now i get:

pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Failed
hookid: terraform_docs

2019/06/25 10:12:16 At 3:15: nested object expected: LBRACE got: ASSIGN

If i take the quotes of the type it works fine. I have removed all the quotes from my main terraform modules variable types and i still get this error:

pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Failed
hookid: terraform_docs

2019/06/25 10:21:17 At 62:1: expected: IDENT | STRING | ASSIGN | LBRACE got: RBRACE

from pre-commit-terraform.

antonbabenko avatar antonbabenko commented on September 19, 2024

Yes, I could reproduce it.

@cytopia Once type is already enquoted it should not enquote it again.

from pre-commit-terraform.

antonbabenko avatar antonbabenko commented on September 19, 2024

Looks like it has been just fixed by @cytopia, so I have released v1.17.0.

from pre-commit-terraform.

thenom avatar thenom commented on September 19, 2024

I am afraid i am still get the same problem:

pre-commit autoupdate
Updating https://github.com/antonbabenko/pre-commit-terraform...[INFO] Initializing environment for https://github.com/antonbabenko/pre-commit-terraform.
updating v1.16.0 -> v1.17.0.
pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Failed
hookid: terraform_docs

2019/06/25 16:35:45 At 62:1: expected: IDENT | STRING | ASSIGN | LBRACE got: RBRACE

from pre-commit-terraform.

cytopia avatar cytopia commented on September 19, 2024

@thenom

I've tested it for the block you pasted above:

variable "test_var" {
  type        = "string"
  description = "This is a test variable"
  default     = ""
}

Maybe there is another exception which is causing it?

from pre-commit-terraform.

thenom avatar thenom commented on September 19, 2024

@cytopia is there anyway i can get this to be more verbose to find out where it is having issues. I cannot rules out this being my tf files but as terraform formats it and runs fine on it i can't see how.

I dont mind spending the time investigating this but would help if there was anything built in that i could enable to start me off.

from pre-commit-terraform.

antonbabenko avatar antonbabenko commented on September 19, 2024

Currently, there is no feature flag to turn on/off debugging, but you can make it easier to guess the failing line by combining all *.tf files into one and by removing everything except variable and output blocks.

Also, even if the code is not valid from terraform_fmt it should be good for terraform_docs, so you can run just it.

from pre-commit-terraform.

cytopia avatar cytopia commented on September 19, 2024

@thenom can you provide all variables and outputs you're using. Otherwise I won't be able to reproduce your error.

from pre-commit-terraform.

thenom avatar thenom commented on September 19, 2024

Ok, i setup a new test folder and ran git init and copied the .pre-commit-yaml from my problematic terraform.

pre-commit run -a
Terraform fmt........................................(no files to check)Skipped
Terraform docs.......................................(no files to check)Skipped

Which was to be expected. I then copied, one by one, each of my tf files over to this folder, ran pre-commit run -a, git add * and then pre-commit run -a again for every file copied.

$ cp ../terraform.module.elasticsearch/security-groups.tf ./
$ pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Passed
$ git add *
$ pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Passed
$ cp ../terraform.module.elasticsearch/variables.tf ./
$ pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Passed
$ git add *
$ pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Passed
... and so on....

I didn't get a single problem...

I then reset this folder back to the initial git init and pre-commit-yaml. I copied all the tf files in one, ran pre-commit run -a, git add * and then pre-commit run -a for the final time and it failed:

$ cp ../terraform.module.elasticsearch/* ./
$ pre-commit run -a
Terraform fmt........................................(no files to check)Skipped
Terraform docs.......................................(no files to check)Skipped
$ git add *
$ pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Failed
hookid: terraform_docs

2019/06/26 16:50:29 At 62:1: expected: IDENT | STRING | ASSIGN | LBRACE got: RBRACE

I then reset and tried it with 2 files in one go and it passed.

With this setup and my single variables.tf, i don't get a problem. I also concated all outputs into a single file and that passed..... The plot thickens....

from pre-commit-terraform.

thenom avatar thenom commented on September 19, 2024

Just incase anyone lands here, after months of using SKIP=terraform_docs on my git commit. for this repo, i recently updated the pre-commit modules and terraform-docs it all now works fine. Hadnt done this for quite a while so not sure when this was fixed.

$ brew upgrade terraform-docs
$ pre-commit autoupdate

(obviously on a mac but i am sure there will be other OS equivalents)

from pre-commit-terraform.

puneeth072003 avatar puneeth072003 commented on September 19, 2024

Hey guys I'm still getting the issue

$  pre-commit run terraform_docs -a
Terraform docs...........................................................Failed
- hook id: terraform_docs
- exit code: 1

May i know how to fix that?

from pre-commit-terraform.

MaxymVlasov avatar MaxymVlasov commented on September 19, 2024

git add -A to add fixes to your git staged changes.

from pre-commit-terraform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.