Skip to content

Commit 8bd42b4

Browse files
authored
Fix panic on obtaining provider schemas (hashicorp#1048)
* Add a test case for a sourced schema without a version. This is now possible since we delay the execution of obtaining the Terraform version. * Only check for a matching schema if we have version and schema.
1 parent 8a410a0 commit 8bd42b4

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

internal/state/provider_schema.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,14 @@ func (s *ProviderSchemaStore) schemaExists(addr tfaddr.Provider, pCons version.C
216216

217217
for item := it.Next(); item != nil; item = it.Next() {
218218
ps, ok := item.(*ProviderSchema)
219-
if ok {
220-
if ps.Schema == nil {
221-
// Incomplete entry may be a result of provider version being
222-
// sourced earlier where schema is yet to be sourced or sourcing failed.
223-
continue
224-
}
219+
if !ok {
220+
continue
221+
}
222+
if ps.Schema == nil || ps.Version == nil {
223+
// Incomplete entries may result from the provider version being
224+
// sourced earlier where the schema is yet to be sourced,
225+
// or vice versa, or sourcing failed.
226+
continue
225227
}
226228

227229
if providerAddrEquals(ps.Address, addr) && pCons.Check(ps.Version) {

internal/state/provider_schema_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,17 @@ func TestAllSchemasExist(t *testing.T) {
877877
ExpectedMatch: true,
878878
ExpectedErr: false,
879879
},
880+
{
881+
Name: "missing provider version in schema store",
882+
Requirements: map[tfaddr.Provider]version.Constraints{
883+
tfaddr.MustParseProviderSource("hashicorp/test"): version.MustConstraints(version.NewConstraint(">=1.0.0")),
884+
},
885+
InstalledProviders: InstalledProviders{
886+
tfaddr.MustParseProviderSource("hashicorp/test"): nil,
887+
},
888+
ExpectedMatch: false,
889+
ExpectedErr: false,
890+
},
880891
}
881892

882893
for _, tc := range testCases {

0 commit comments

Comments
 (0)