fix: include providers from test files in lock command #37880
+39
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
The
terraform providers lockcommand wasn't picking up providers from test files. This fixes that.What was the issue?
So basically, when you had a
.tftest.hclfile that referenced a provider, runningterraform providers lockwouldn't include it in the lock file. That's because the code was only loading the root config and completely ignoring test files.How'd you fix it?
Changed one line really. Was doing
loadConfig(".")which doesn't touch test files. Now it'sloadConfigWithTests(".", "tests")so it actually loads them. The provider requirements extraction already supported test files, we just weren't loading them in the first place.Changes
providers_lock.go- one line change to use the right config loaderproviders_lock_test.go- added a test case to catch this if it happens againTesting
Ran the test suite and everything passes:
go test -v ./internal/command -run TestProvidersLockAlso manually tested with the actual
terraform providers lockcommand - works perfectly.Got the new test case passing and didn't break anything else.
Fixes
#37841