Skip to content

Reinitialize if module version requirement changed #299

Description

@jgrumboe

What problem are you facing?

I wanted to switch from gruntwork/terraform-validate pre-commit hook to pre-commit-terraform/terraform_validate. So far so good, but when I changed a module version in my code I got the following error:

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

Validation failed: XXXXXXX/production

Error: Module version requirements have changed

  on main.tf line 17, in module "base":
  17:   source                            = "app.terraform.io/XXXXXX/base/aws"

The version requirements have changed since this module was installed and the
installed version (2.0.10-pre) is no longer acceptable. Run "terraform init"
to install all modules required by this configuration.

I never got such an error with the gruntwork hook and I figured out that the gruntwork hook just always run terraform init -backend=false.
The terraform_validate hook only runs terraform init if there's no .terraform directory --> https://github.com/antonbabenko/pre-commit-terraform/blob/master/terraform_validate.sh#L93

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

Honestly, I'm a fan of not running terraform init all the time, as it makes pre-commit checks faster overall.
On the other side I don't like to think about manually deleting .terraform and terraform.lock.hcl whenever I want to change to a different module version.

It would be great of terraform_validate would be aware of module version changes and rerun terraform init if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions