Skip to content
Merged
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.14/BUG FIXES-20251104-122322.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: BUG FIXES
body: 'query: improve error handling for missing identity schemas'
time: 2025-11-04T12:23:22.096828+01:00
custom:
Issue: "37863"
2 changes: 1 addition & 1 deletion internal/plugin/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ func (p *GRPCProvider) ListResource(r providers.ListResourceRequest) providers.L

resourceSchema, ok := schema.ResourceTypes[r.TypeName]
if !ok || resourceSchema.Identity == nil {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("identity schema not found for resource type %s", r.TypeName))
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("Identity schema not found for resource type %s; this is a bug in the provider - please report it there", r.TypeName))
return resp
}

Expand Down
2 changes: 1 addition & 1 deletion internal/plugin6/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ func (p *GRPCProvider) ListResource(r providers.ListResourceRequest) providers.L

resourceSchema, ok := schema.ResourceTypes[r.TypeName]
if !ok || resourceSchema.Identity == nil {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("identity schema not found for resource type %s", r.TypeName))
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("Identity schema not found for resource type %s; this is a bug in the provider - please report it there", r.TypeName))
return resp
}

Expand Down
51 changes: 49 additions & 2 deletions internal/terraform/context_plan_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,10 @@ func TestContext2Plan_queryList(t *testing.T) {
if tc.transformSchema != nil {
tc.transformSchema(provider.GetProviderSchemaResponse)
}
var requestConfigs = make(map[string]cty.Value)
provider.ListResourceFn = func(request providers.ListResourceRequest) providers.ListResourceResponse {
if request.Config.IsNull() || request.Config.GetAttr("config").IsNull() {
t.Fatalf("config should never be null, got null for %s", request.TypeName)
}
requestConfigs[request.TypeName] = request.Config
return listResourceFn(request)
}

Expand Down Expand Up @@ -948,6 +946,55 @@ func TestContext2Plan_queryListArgs(t *testing.T) {
}
}

func TestContext2Plan_queryListDiags(t *testing.T) {
configFiles := map[string]string{}
configFiles["main.tf"] = `
terraform {
required_providers {
test = {
source = "hashicorp/test"
version = "1.0.0"
}
}
}`
configFiles["main.tfquery.hcl"] = `
list "test_resource" "test1" {
provider = test
}`
mod := testModuleInline(t, configFiles, configs.MatchQueryFiles())

providerAddr := addrs.NewDefaultProvider("test")
provider := testProvider("test")
provider.ConfigureProvider(providers.ConfigureProviderRequest{})
provider.GetProviderSchemaResponse = getListProviderSchemaResp()
provider.ListResourceFn = func(request providers.ListResourceRequest) providers.ListResourceResponse {
if request.Config.IsNull() || request.Config.GetAttr("config").IsNull() {
t.Fatalf("config should never be null, got null for %s", request.TypeName)
}

resp := providers.ListResourceResponse{}
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("Identity schema not found for resource type %s; this is a bug in the provider - please report it there", request.TypeName))

return resp
}

ctx, diags := NewContext(&ContextOpts{
Providers: map[addrs.Provider]providers.Factory{
providerAddr: testProviderFuncFixed(provider),
},
})
tfdiags.AssertNoDiagnostics(t, diags)

_, diags = ctx.Plan(mod, states.NewState(), &PlanOpts{
Mode: plans.NormalMode,
SetVariables: testInputValuesUnset(mod.Module.Variables),
Query: true,
})
if len(diags) != 1 {
t.Fatalf("expected 1 diagnostics, got %d \n - diags: %s", len(diags), diags)
}
}

// getListProviderSchemaResp returns a mock provider schema response for testing list resources.
// THe schema returned here is a mock of what the internal protobuf layer would return
// for a provider that supports list resources.
Expand Down
8 changes: 4 additions & 4 deletions internal/terraform/node_resource_plan_instance_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func (n *NodePlannableResourceInstance) listResourceExecute(ctx EvalContext) (di
Limit: limit,
IncludeResourceObject: includeRsc,
})
diags = diags.Append(resp.Diagnostics.InConfigBody(config.Config, n.Addr.String()))
if diags.HasErrors() {
return diags
}
results := plans.QueryResults{
Value: resp.Result,
}
Expand All @@ -132,10 +136,6 @@ func (n *NodePlannableResourceInstance) listResourceExecute(ctx EvalContext) (di
ctx.Hook(func(h Hook) (HookAction, error) {
return h.PostListQuery(rId, results, identityVersion)
})
diags = diags.Append(resp.Diagnostics.InConfigBody(config.Config, n.Addr.String()))
if diags.HasErrors() {
return diags
}

query := &plans.QueryInstance{
Addr: n.Addr,
Expand Down