Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/v1.15/BUG FIXES-20251106-065000.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: BUG FIXES
body: 'command: terraform providers lock now includes providers required by test files'
time: 2025-11-06T06:50:00.000000Z
custom:
Issue: "37841"
2 changes: 1 addition & 1 deletion internal/command/providers_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (c *ProvidersLockCommand) Run(args []string) int {
source = getproviders.NewRegistrySource(c.Services)
}

config, confDiags := c.loadConfig(".")
config, confDiags := c.loadConfigWithTests(".", "tests")
diags = diags.Append(confDiags)
reqs, hclDiags := config.ProviderRequirements()
diags = diags.Append(hclDiags)
Expand Down
17 changes: 17 additions & 0 deletions internal/command/providers_lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ provider "registry.terraform.io/hashicorp/test" {
"h1:invalid",
]
}
`
runProviderLockGenericTest(t, testDirectory, expected)
})

// This test ensures that providers required by test modules are included
// in the lock file. This is a regression test for issue #37841.
t.Run("with-tests", func(t *testing.T) {
testDirectory := "providers-lock/with-tests"
expected := `# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.

provider "registry.terraform.io/hashicorp/test" {
version = "1.0.0"
hashes = [
"h1:7MjN4eFisdTv4tlhXH5hL4QQd39Jy4baPhFxwAd/EFE=",
]
}
`
runProviderLockGenericTest(t, testDirectory, expected)
})
Expand Down
7 changes: 7 additions & 0 deletions internal/command/testdata/providers-lock/with-tests/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
test = {
source = "hashicorp/test"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
provider "test" {
alias = "runner"
}

run "test_run" {
providers = {
test = test.runner
}
}