Skip to content

Commit 1761c81

Browse files
committed
fix: include providers from test files in lock command
Fixes #37841
1 parent 9595517 commit 1761c81

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: 'command: terraform providers lock now includes providers required by test files'
3+
time: 2025-11-06T06:50:00.000000Z
4+
custom:
5+
Issue: "37841"

internal/command/providers_lock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (c *ProvidersLockCommand) Run(args []string) int {
123123
source = getproviders.NewRegistrySource(c.Services)
124124
}
125125

126-
config, confDiags := c.loadConfig(".")
126+
config, confDiags := c.loadConfigWithTests(".", "tests")
127127
diags = diags.Append(confDiags)
128128
reqs, hclDiags := config.ProviderRequirements()
129129
diags = diags.Append(hclDiags)

internal/command/providers_lock_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ provider "registry.terraform.io/hashicorp/test" {
6666
"h1:invalid",
6767
]
6868
}
69+
`
70+
runProviderLockGenericTest(t, testDirectory, expected)
71+
})
72+
73+
// This test ensures that providers required by test modules are included
74+
// in the lock file. This is a regression test for issue #37841.
75+
t.Run("with-tests", func(t *testing.T) {
76+
testDirectory := "providers-lock/with-tests"
77+
expected := `# This file is maintained automatically by "terraform init".
78+
# Manual edits may be lost in future updates.
79+
80+
provider "registry.terraform.io/hashicorp/test" {
81+
version = "1.0.0"
82+
hashes = [
83+
"h1:7MjN4eFisdTv4tlhXH5hL4QQd39Jy4baPhFxwAd/EFE=",
84+
]
85+
}
6986
`
7087
runProviderLockGenericTest(t, testDirectory, expected)
7188
})

internal/command/testdata/providers-lock/with-tests/fs-mirror/registry.terraform.io/hashicorp/test/1.0.0/os_arch/terraform-provider-test

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
terraform {
2+
required_providers {
3+
test = {
4+
source = "hashicorp/test"
5+
}
6+
}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
provider "test" {
2+
alias = "runner"
3+
}
4+
5+
run "test_run" {
6+
providers = {
7+
test = test.runner
8+
}
9+
}

0 commit comments

Comments
 (0)