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

hook terraform validate fails #203

Closed
loque1 opened this issue Jun 3, 2021 · 8 comments
Closed

hook terraform validate fails #203

loque1 opened this issue Jun 3, 2021 · 8 comments
Assignees
Labels
bug_with_workaround Something isn't working but there is a workaround documentation Improvements or additions to documentation estimate/1h Need 1 hour to be done hook/terraform_validate Bash hook wontfix This will not be worked on

Comments

@loque1
Copy link

loque1 commented Jun 3, 2021

Hi. I upgraded to terraform 0.15.4 and the terraform_validate hook fails with the following

Terraform validate.......................................................Failed
- hook id: terraform_validate
- exit code: 1

Validation failed: iac/common
╷
│ Warning: Experimental feature "module_variable_optional_attrs" is active
│ 
│   on terraform.tf line 13, in terraform:
│   13:   experiments = [module_variable_optional_attrs]
│ 
│ Experimental features are subject to breaking changes in future minor or
│ patch releases, based on feedback.
│ 
│ If you have feedback on the design of this feature, please open a GitHub
│ issue to discuss it.
╵
╷
│ Error: Could not load plugin
│ 
│ 
│ Plugin reinitialization required. Please run "terraform init".
│ 
│ Plugins are external binaries that Terraform uses to access and manipulate
│ resources. The configuration provided requires plugins which can't be
│ located,
│ don't satisfy the version constraints, or are otherwise incompatible.
│ 
│ Terraform automatically discovers provider requirements from your
│ configuration, including providers used in child modules. To see the
│ requirements and constraints, run "terraform providers".
│ 
│ 2 problems:
│ 
│ - failed to instantiate provider "registry.terraform.io/hashicorp/azuread"
│ to obtain schema: unknown provider
│ "registry.terraform.io/hashicorp/azuread"
│ - failed to instantiate provider "registry.terraform.io/hashicorp/azurerm"
│ to obtain schema: unknown provider
│ "registry.terraform.io/hashicorp/azurerm"
│ 
╵

If I run the command outside of pre-commit in the same directory it all passes fine

╷
│ Warning: Experimental feature "module_variable_optional_attrs" is active
│ 
│   on terraform.tf line 13, in terraform:
│   13:   experiments = [module_variable_optional_attrs]
│ 
│ Experimental features are subject to breaking changes in future minor or patch releases, based on feedback.
│ 
│ If you have feedback on the design of this feature, please open a GitHub issue to discuss it.
│ 
│ (and 5 more similar warnings elsewhere)
╵
Success! The configuration is valid, but there were some validation warnings as shown above.

Any help on this would be ideal

@mustafababil
Copy link

You can try deleting your .terraform folder as you upgraded TF version earlier.

@amontalban
Copy link

I'm having the same issue when running in a pipeline in Codefresh with a repository with multiple Terraform modules, I have tried to delete all .terraform folders, do a git clean -f -x and even cloning in a random directory.

I thought #158 would have fixed it but not in my case.

Any idea on how to debug this in a pipeline?

Thanks!

@jimsmith
Copy link

jimsmith commented Sep 3, 2021

I ran into this same issue, the way I got it to work was remove all .terraform directories including one's in modules directories as in my case it was created locally and when this came along it would not bring in the other providers until I nuked the .terraform folders across the project.

Before

Terraform validate.......................................................Failed
- hook id: terraform_validate
- exit code: 1

Validation failed: terraform/modules/aws-vpn-client
╷
│ Error: Could not load plugin
│ 
│ 
│ Plugin reinitialization required. Please run "terraform init".
│ 
│ Plugins are external binaries that Terraform uses to access and manipulate
│ resources. The configuration provided requires plugins which can't be
│ located,
│ don't satisfy the version constraints, or are otherwise incompatible.
│ 
│ Terraform automatically discovers provider requirements from your
│ configuration, including providers used in child modules. To see the
│ requirements and constraints, run "terraform providers".
│ 
│ 2 problems:
│ 
│ - failed to instantiate provider "registry.terraform.io/hashicorp/null" to
│ obtain schema: unknown provider "registry.terraform.io/hashicorp/null"
│ - failed to instantiate provider "registry.terraform.io/hashicorp/template"
│ to obtain schema: unknown provider
│ "registry.terraform.io/hashicorp/template"
│ 
╵

After

 pre-commit run --all-files terraform_validate
Terraform validate.......................................................Passed

@antonbabenko
Copy link
Owner

I do the same as @jimsmith . Here is my shell function for that:

rm_terraform () {
        find . -name ".terraform*" -print0 | xargs -0 rm -r
}

@MaxymVlasov MaxymVlasov added hook/terraform_validate Bash hook bug_with_workaround Something isn't working but there is a workaround estimate/1h Need 1 hour to be done documentation Improvements or additions to documentation labels Sep 3, 2021
@MaxymVlasov MaxymVlasov self-assigned this Sep 3, 2021
@MaxymVlasov
Copy link
Collaborator

TBD: add workaround to docs

@MaxymVlasov MaxymVlasov added the wontfix This will not be worked on label Sep 3, 2021
@MaxymVlasov MaxymVlasov added this to the Bug and docs fixes milestone Sep 9, 2021
@eytanhanig
Copy link

Deleting all .terraform has consequences for local developmen if you're using Terraform workspaces, which create the file .terraform/environment. A better solution for this module would be to add an argument to terraform_validate or create separate hook altogether that specifies cases when you always want to run terraform init before running terraform validate.

@antonbabenko
Copy link
Owner

Very good point! Let's add support for an argument in terraform_validate like force-init.

@MaxymVlasov
Copy link
Collaborator

TBD: add workaround to docs

Done

Issue closing reasons:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug_with_workaround Something isn't working but there is a workaround documentation Improvements or additions to documentation estimate/1h Need 1 hour to be done hook/terraform_validate Bash hook wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

7 participants