hashicorp/terraform · error

identity schema not found for type %s

Error message

identity schema not found for type %s

What it means

Returned inside the gRPC v6 provider wrapper (internal/grpcwrap/provider6.go:616, in MoveResourceState) when MoveResourceState's response carries a non-null TargetIdentity but the target resource type's schema in p.schema.ResourceTypes has a nil Identity block. The wrapper needs resSchema.Identity.ImpliedType() to encode the identity value, so a missing identity schema makes encoding impossible. The same literal appears at several other RPC handlers (ReadResource:302/334, PlanResourceChange:382/420, ApplyResourceChange:470/504, ImportResourceState:528/559) but index 944 pins line 616.

Source

Thrown at internal/grpcwrap/provider6.go:616

		TargetTypeName:        request.TargetTypeName,
		SourceIdentity:        sourceIdentity,
	})
	resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, moveResp.Diagnostics)
	if moveResp.Diagnostics.HasErrors() {
		return resp, nil
	}

	targetSchema := p.schema.ResourceTypes[request.TargetTypeName]
	targetType := targetSchema.Body.ImpliedType()
	targetState, err := encodeDynamicValue6(moveResp.TargetState, targetType)
	if err != nil {
		resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
		return resp, nil
	}

	if !moveResp.TargetIdentity.IsNull() {
		if targetSchema.Identity == nil {
			return resp, fmt.Errorf("identity schema not found for type %s", request.TargetTypeName)
		}

		targetIdentity, err := encodeDynamicValue6(moveResp.TargetIdentity, targetSchema.Identity.ImpliedType())
		if err != nil {
			resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
			return resp, nil
		}

		resp.TargetIdentity = &tfplugin6.ResourceIdentityData{
			IdentityData: targetIdentity,
		}
	}

	resp.TargetState = targetState
	resp.TargetPrivate = moveResp.TargetPrivate
	return resp, nil
}

View on GitHub (pinned to c9def3e214)

Solutions

  1. Ensure the target resource type's schema (GetProviderSchema) declares an Identity block whenever the provider may return identity data for it.
  2. Align the Terraform core version with the provider version so both understand resource identities.
  3. If authoring a test provider behind grpcwrap.Provider6, populate provider6.identitySchemas/schema consistently in the providers.Interface implementation.
  4. Report to the provider if the schema genuinely omits Identity yet the provider emits one (provider-side bug).

Example fix

// before (provider schema omits Identity but MoveResourceState returns identity)
schema.ResourceTypes["aws_instance"].Identity = nil
moveResp.TargetIdentity = cty.ObjectVal(...)  // -> identity schema not found for type aws_instance

// after
schema.ResourceTypes["aws_instance"].Identity = providers.ResourceIdentitySchema{ /* fields */ }
Defensive patterns

Strategy: validation

Validate before calling

// When wrapping a provider, assert schema/identity consistency up front:
func validateIdentitySchemas(s providers.GetProviderSchemaResponse) error {
    for typ, rs := range s.ResourceTypes {
        _ = typ; _ = rs.Identity // document the contract
    }
    return nil
}

Type guard

func typeHasIdentitySchema(s providers.GetProviderSchemaResponse, typ string) bool {
    rs, ok := s.ResourceTypes[typ]
    return ok && rs.Identity != nil
}

Try / catch

// On the gRPC server side the error is terminal; clients should guard before sending identity:
if !typeHasIdentitySchema(schema, req.TypeName) {
    req.TargetIdentity = cty.NullVal(cty.DynamicPseudoType)
}

Prevention

When it happens

Trigger: A provider returns a populated identity (moveResp.TargetIdentity is not null) for a resource type whose schema declares no ResourceIdentity block; specifically during terraform state move/import where the wrapper tries to encode the returned identity. Caused by a provider bug or a schema/identity mismatch across provider versions.

Common situations: Upgrading a provider that started emitting identities to a Terraform core version that recorded a schema without the Identity block; a provider's GetProviderSchema reporting Identity for some types but not the type being moved; test harnesses wrapping a mock provider that returns identity without declaring it.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/dd98717a18688ecd. Report an issue: GitHub.