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

terraform_validate hook doesn't run terraform init if a provider is not installed even when using --retry-once-with-cleanup=true #585

Closed
fwolfheimer opened this issue Nov 15, 2023 · 1 comment · Fixed by #586
Labels

Comments

@fwolfheimer
Copy link
Contributor

fwolfheimer commented Nov 15, 2023

Describe the bug

In a situation where the Terraform providers are not installed the terraform_validate hook doesn't execute terraform init to install the providers even if the hook is configured with the option --retry-once-with-cleanup=true. I ran in a situation where the terraform_validate hook terminated with an error showing the following error output (from Terraform apparently):

Validation failed: my-project
{
  "format_version": "1.0",
  "valid": false,
  "error_count": 6,
  "warning_count": 0,
  "diagnostics": [
    {
      "severity": "error",
      "summary": "Missing required provider",
      "detail": "This configuration requires provider registry.terraform.io/hashicorp/external, but that provider isn't available. You may be able to install it automatically by running:
  terraform init"
    },
    {
      "severity": "error",
      "summary": "Missing required provider",
      "detail": "This configuration requires provider registry.terraform.io/hashicorp/google, but that provider isn't available. You may be able to install it automatically by running:
  terraform init"
    },
    {
      "severity": "error",
      "summary": "Missing required provider",
      "detail": "This configuration requires provider registry.terraform.io/hashicorp/null, but that provider isn't available. You may be able to install it automatically by running:
  terraform init"
    },
    {
      "severity": "error",
      "summary": "Missing required provider",
      "detail": "This configuration requires provider registry.terraform.io/hashicorp/random, but that provider isn't available. You may be able to install it automatically by running:
  terraform init"
    },
    {
      "severity": "error",
      "summary": "Missing required provider",
      "detail": "This configuration requires provider registry.terraform.io/hashicorp/tls, but that provider isn't available. You may be able to install it automatically by running:
  terraform init"
    },
    {
      "severity": "error",
      "summary": "Missing required provider",
      "detail": "This configuration requires provider registry.terraform.io/techbeck03/guacamole, but that provider isn't available. You may be able to install it automatically by running:
  terraform init"
    }
  ]
}

The problem is that the function match_validate_errors in the terraform_validate.sh script doesn't have the error Missing required provider in its list of errors for which terraform init should be called to fix them.

How can we reproduce it?

Use it with a fresh TF config where no provider has been installed, yet.

@antonbabenko
Copy link
Owner

This issue has been resolved in version 1.83.6 🎉

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

Successfully merging a pull request may close this issue.

3 participants