pulumi / pulumi-terraform-provider

Use any Terraform provider with Pulumi
Apache License 2.0
6 stars 0 forks source link

panic: UNKNOWN TYPE of tftypes.primitive{name:"DynamicPseudoType", _:[]struct {}(nil)} #7

Closed lukehoban closed 2 months ago

lukehoban commented 3 months ago

When I tried to use gen-sdk on the hashicopr/kubernetes provider I get this panic:

 % pulumi package gen-sdk terraform-provider --language python --out kubernetes -- hashicorp/kubernetes
panic: UNKNOWN TYPE of tftypes.primitive{name:"DynamicPseudoType", _:[]struct {}(nil)}

goroutine 193 [running]:

github.com/pulumi/pulumi-terraform-bridge/pf/proto.element.Type({{0x104defc90?, 0x14000d78a50?}, 0x70?})

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pf/proto/element.go:56 +0x274

github.com/pulumi/pulumi-terraform-bridge/pf/proto.attribute.Type({{{0x14000c5c3c0, 0x8}, {0x104defc90, 0x14000d78a50}, 0x0, {0x1400088dce0, 0x51}, 0x1, 0x0, 0x0, ...}})

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pf/proto/attribute.go:44 +0x7c

github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info.MarshalSchemaShim({0x104dfe610, 0x140010d0af0})

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pkg/tfbridge/info/info.go:831 +0x2c

github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info.MarshalResourceShim.func1({0x14000c5c3c0, 0x8}, {0x104dfe610?, 0x140010d0af0?})

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pkg/tfbridge/info/info.go:868 +0x3c

github.com/pulumi/pulumi-terraform-bridge/pf/proto.blockMap.Range({0x14000e5b828?}, 0x1400090f080)

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pf/proto/block.go:74 +0xe4

github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info.MarshalResourceShim({0x104dee6b0, 0x14001c06a00})

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pkg/tfbridge/info/info.go:867 +0xa4

github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info.MarshalProviderShim.func2({0x14000c02828, 0x13}, {0x104dee6b0?, 0x14001c06a00?})

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pkg/tfbridge/info/info.go:936 +0x3c

github.com/pulumi/pulumi-terraform-bridge/pf/proto.resourceMap.Range(0x0?, 0x14001e051a0)

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pf/proto/resource.go:51 +0x88

github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info.MarshalProviderShim({0x104dfe838, 0x140000b3680})

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pkg/tfbridge/info/info.go:935 +0x10c

github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info.MarshalProvider(0x14000e5baa8)

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pkg/tfbridge/info/info.go:1182 +0x280

github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge.MarshalProviderInfo(...)

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pkg/tfbridge/info.go:267

github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.newInMemoryProvider({_, _}, {_, _, _}, {{0x104dfe838, 0x140000b3680}, {0x1400091058c, 0xa}, {0x0, ...}, ...})

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pkg/tfgen/pluginHost.go:48 +0x34

github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.NewGenerator({{0x1400091058c, 0xa}, {0x14000d86066, 0x6}, {0x103fd174d, 0x6}, {{0x104dfe838, 0x140000b3680}, {0x1400091058c, 0xa}, ...}, ...})

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pkg/tfgen/generate.go:875 +0x4e8

github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.GenerateSchemaWithOptions({{{0x104dfe838, 0x140000b3680}, {0x1400091058c, 0xa}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, ...}, ...})

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pkg/tfgen/generate.go:770 +0x11c

main.initialSetup.func2({0x14000715188?, 0x104de1238?}, {0x14001e3ab10?, {0x0?, 0x0?}, 0x0?})

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/dynamic/main.go:64 +0xe0

github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge.(*provider).GetSchemaWithContext(0x14000715188, {0x104de1238?, 0x14001e3ab10?}, {0x1028dc02c?, {0x1400000edb0?, 0x91?}, 0x14000116280?})

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pf/tfbridge/provider.go:227 +0x78

github.com/pulumi/pulumi-terraform-bridge/pf/internal/plugin.(*providerServer).GetSchema(0x14000737320?, {0x104de1238?, 0x14001e3ab10?}, 0x140001160f0?)

        /home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pf/internal/plugin/provider_server.go:176 +0x1b8

github.com/pulumi/pulumi/sdk/v3/proto/go._ResourceProvider_GetSchema_Handler.func1({0x104de1238?, 0x14001e3ab10?}, {0x104c14500?, 0x140001160f0?})

        /home/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.125.1-0.20240720005025-a3aef6c6522f/proto/go/provider_grpc.pb.go:486 +0xd0

github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc.OpenTracingServerInterceptor.func1({0x104de1238, 0x14001e3a540}, {0x104c14500, 0x140001160f0}, 0x140007ea220, 0x14001c919e0)

        /home/runner/go/pkg/mod/github.com/grpc-ecosystem/grpc-opentracing@v0.0.0-20180507213350-8e809c8a8645/go/otgrpc/server.go:57 +0x2e4

github.com/pulumi/pulumi/sdk/v3/proto/go._ResourceProvider_GetSchema_Handler({0x104d54620, 0x14000737320}, {0x104de1238, 0x14001e3a540}, 0x140002a8080, 0x14000b26420)

        /home/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.125.1-0.20240720005025-a3aef6c6522f/proto/go/provider_grpc.pb.go:488 +0x148

google.golang.org/grpc.(*Server).processUnaryRPC(0x140006fea00, {0x104de1238, 0x14001e3a3f0}, {0x104df49e0, 0x14000b82000}, 0x14000bac6c0, 0x140007373b0, 0x10608c118, 0x0)

        /home/runner/go/pkg/mod/google.golang.org/grpc@v1.63.2/server.go:1369 +0xb58

google.golang.org/grpc.(*Server).handleStream(0x140006fea00, {0x104df49e0, 0x14000b82000}, 0x14000bac6c0)

        /home/runner/go/pkg/mod/google.golang.org/grpc@v1.63.2/server.go:1780 +0xb20

google.golang.org/grpc.(*Server).serveStreams.func2.1()

        /home/runner/go/pkg/mod/google.golang.org/grpc@v1.63.2/server.go:1019 +0x8c

created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 84

        /home/runner/go/pkg/mod/google.golang.org/grpc@v1.63.2/server.go:1030 +0x13c

error: rpc error: code = Unavailable desc = error reading from server: EOF
mjeffryes commented 3 months ago

This panic seems to stem from trying to convert an UNKNOWN type in the schema. ("DynamicPseudoType" is used for UNKNOWN types in tftypes). This happens when we try to convert the schema from the TF provider into something marshalable (https://github.com/pulumi/pulumi-terraform-bridge/blob/8ab4fdc9c24f32b170f814f0ff1b4a8d50c738f2/pkg/tfbridge/info/info.go#L831C1-L831C32) to send to the engine.

It looks like it's coming from down in some resource schema, so my bet - given that this is a kubernetes provider - is that there's some part of a resource schema that is left undefined if the provider can't read a kubconfig file to access the cluster.

We can start by just converting this panic into a warning or error about not being able to get the schema for this resource. It may be tricky to generically create a useful error as to why resources have undefined types though. Specific causes will probably vary quite a bit (Though usually something missing from config or env I would guess).

mjeffryes commented 3 months ago

actually, based on https://github.com/pulumi/pulumi-terraform-bridge/blob/8ab4fdc9c24f32b170f814f0ff1b4a8d50c738f2/pf/internal/schemashim/convert_type.go#L45, I wonder if the correct local fix for the panic would be to return shim.TypeDyanmic. This would cause an error later in when trying to generate the pulumi schema: (https://github.com/pulumi/pulumi-terraform-bridge/blob/8ab4fdc9c24f32b170f814f0ff1b4a8d50c738f2/pkg/tfgen/generate.go#L444). I think that error gets handled at least somewhat reasonably higher up the call chain, and we could possibly add some special handling in the dynamic provider top level to add at least some hint to the user what this kind of failure means.

cleverguy25 commented 3 months ago

Added to epic https://github.com/pulumi/home/issues/3371