Skip to content

Conversation

@vietcgi
Copy link
Contributor

@vietcgi vietcgi commented Nov 6, 2025

Summary

The terraform providers lock command wasn't picking up providers from test files. This fixes that.

What was the issue?

So basically, when you had a .tftest.hcl file that referenced a provider, running terraform providers lock wouldn'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's loadConfigWithTests(".", "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 loader
  • providers_lock_test.go - added a test case to catch this if it happens again
  • Some test fixtures showing what a config with test file providers looks like

Testing

Ran the test suite and everything passes:

go test -v ./internal/command -run TestProvidersLock

Also manually tested with the actual terraform providers lock command - works perfectly.

Got the new test case passing and didn't break anything else.

Fixes

#37841

@vietcgi vietcgi requested a review from a team as a code owner November 6, 2025 15:00
@vietcgi vietcgi force-pushed the fix/providers-lock-with-tests branch from 3213d1f to 1761c81 Compare November 6, 2025 15:03
@zanecodes
Copy link

Awesome, glad to see that this fix is so straightforward!

The base terraform providers command accepts a -test-directory argument, just like terraform test does, to specify a custom testing directory. It doesn't look like terraform providers schema or terraform providers mirror support it though. Would it make sense to add support for -test-directory to terraform providers lock, to allow for custom testing directories?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants