Skip to content

fix(tflint): Handle the absence of `.terraform.lock.hcl` gracefully.

Florian Forster requested to merge fforster/tflint into main

What

tflint: Handle the absence of .terraform.lock.hcl gracefully.

Why

The function find_tf_modules() falls back to searching for *.tf if .terraform.lock.hcl does not exist.

However, in that case terraform init fails due to the -lockfile=readonly flag with the following unintuitive error message:

Error: Provider dependency changes detected

Changes to the required provider dependencies were detected, but the lock file is read-only. To use and record these requirements, run "terraform init" without the "-lockfile=readonly" flag.

Example error: https://gitlab.com/gitlab-com/gl-infra/platform/runway/runwayctl/-/jobs/6443956823

With this change, the -lockfile=readonly flag is only passed if .terraform.lock.hcl exists. Otherwise, a warning is printed.

Example successful run: https://gitlab.com/gitlab-com/gl-infra/platform/runway/runwayctl/-/jobs/6444463950

Edited by Florian Forster

Merge request reports