pulumi / pulumi-gcp

A Google Cloud Platform (GCP) Pulumi resource package, providing multi-language access to GCP
Apache License 2.0
184 stars 52 forks source link

invalid memory address or nil pointer dereference when using container.Cluster.get #1210

Open nattawitc opened 1 year ago

nattawitc commented 1 year ago

What happened?

container.Cluster.get failed when using location argument.

Example

from pulumi_gcp.container import Cluster

Cluster.get(
    resource_name="test",
    id="clustername",
    location="asia-northeast1-a",
)

pulumi preview

Diagnostics:
  pulumi:pulumi:Stack (getting-start):
    error: preview failed

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x105501968]
    goroutine 103 [running]:
    github.com/hashicorp/terraform-provider-google-beta/google-beta/services/container.resourceContainerClusterRead(0x14005985400, {0x106a5e7c0?, 0x140064a4a80?})
        /home/runner/work/pulumi-gcp/pulumi-gcp/upstream/google-beta/services/container/resource_container_cluster.go:2439 +0x14c8
    github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x106acb610?, {0x106acb610?, 0x1400011e008?}, 0xd?, {0x106a5e7c0?, 0x140064a4a80?})
        /home/runner/go/pkg/mod/github.com/pulumi/terraform-plugin-sdk/v2@v2.0.0-20230710100801-03a71d0fca3d/helper/schema/resource.go:743 +0x134
    github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x14000c6cee0, {0x106acb610, 0x1400011e008}, 0x140066348f0, {0x106a5e7c0, 0x140064a4a80})
        /home/runner/go/pkg/mod/github.com/pulumi/terraform-plugin-sdk/v2@v2.0.0-20230710100801-03a71d0fca3d/helper/schema/resource.go:1049 +0x46c
    github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2.v2Provider.Refresh({0x140000a36e0?, {0x0?, 0x1061b9e00?, 0x14006505530?}}, {0x1058037c0, 0x18}, {0x106accc28?, 0x140059bbad0})
        /home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/v3@v3.55.0/pkg/tfshim/sdk-v2/provider.go:113 +0x118
    github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge.(*Provider).Read(0x140003d2580, {0x106acb680?, 0x14006524f60?}, 0x14005b2f2c0)
        /home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/v3@v3.55.0/pkg/tfbridge/provider.go:828 +0x52c
    github.com/pulumi/pulumi-terraform-bridge/x/muxer.(*muxer).Read.func1({0x106adc540?, 0x140003d2580?})
        /home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/x/muxer@v0.0.4/muxer.go:350 +0x3c
    github.com/pulumi/pulumi-terraform-bridge/x/muxer.resourceMethod[...](0x140005e2d20?, 0x140010d7778, 0x140010d7758?)
        /home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/x/muxer@v0.0.4/muxer.go:303 +0xc4
    github.com/pulumi/pulumi-terraform-bridge/x/muxer.(*muxer).Read(0x140010d77b8?, {0x106acb680?, 0x14006524f60?}, 0x1061f3940?)
        /home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/x/muxer@v0.0.4/muxer.go:349 +0x5c
    github.com/pulumi/pulumi/sdk/v3/proto/go._ResourceProvider_Read_Handler.func1({0x106acb680, 0x14006524f60}, {0x106768340?, 0x14005b2f2c0})
        /home/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.76.1/proto/go/provider_grpc.pb.go:591 +0x74
    github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc.OpenTracingServerInterceptor.func1({0x106acb680, 0x14006524c60}, {0x106768340, 0x14005b2f2c0}, 0x140059b1440, 0x140059bb728)
        /home/runner/go/pkg/mod/github.com/grpc-ecosystem/grpc-opentracing@v0.0.0-20180507213350-8e809c8a8645/go/otgrpc/server.go:57 +0x2f4
    github.com/pulumi/pulumi/sdk/v3/proto/go._ResourceProvider_Read_Handler({0x106a13800?, 0x140005e2d20}, {0x106acb680, 0x14006524c60}, 0x14006526690, 0x14000a1e5c0)
        /home/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.76.1/proto/go/provider_grpc.pb.go:593 +0x12c
    google.golang.org/grpc.(*Server).processUnaryRPC(0x14001848000, {0x106ad7b60, 0x140059881a0}, 0x14006522900, 0x140059285d0, 0x109d77918, 0x0)
        /home/runner/go/pkg/mod/google.golang.org/grpc@v1.56.2/server.go:1337 +0xc28
    google.golang.org/grpc.(*Server).handleStream(0x14001848000, {0x106ad7b60, 0x140059881a0}, 0x14006522900, 0x0)
        /home/runner/go/pkg/mod/google.golang.org/grpc@v1.56.2/server.go:1714 +0x80c
    google.golang.org/grpc.(*Server).serveStreams.func1.1()
        /home/runner/go/pkg/mod/google.golang.org/grpc@v1.56.2/server.go:959 +0x84
    created by google.golang.org/grpc.(*Server).serveStreams.func1
        /home/runner/go/pkg/mod/google.golang.org/grpc@v1.56.2/server.go:957 +0x164

  gcp:container:Cluster (test):
    error: Preview failed: error reading from server: EOF

Output of pulumi about

CLI
Version 3.84.0 Go Version go1.21.1 Go Compiler gc

Plugins NAME VERSION crds 0.0.0 gcp 6.62.0 kubernetes 4.1.1 python unknown

Host
OS darwin Version 13.5.1 Arch arm64

This project is written in python: executable='/Users/nattawit.chaiworawit/test/pulumi/getting-start/venv/getting-start/bin/python3' version='3.11.4 '

Backend
Name JP-MGXF2K3024 URL file://~ User nattawit.chaiworawit Organizations

Dependencies: NAME VERSION charset-normalizer 3.2.0 pip 23.0.1 pulumi-crds 0.0.0 pulumi-gcp 6.62.0 pulumi-kubernetes 4.1.1 setuptools 67.6.1

Pulumi locates its logs in /var/folders/r1/ll67djrj4nzfqz6c7slg25ln06fcrx/T/ by default warning: Failed to get information about the current stack: No current stack

Additional context

it seems to work when moving the location to id instead

from pulumi_gcp.container import Cluster

Cluster.get(
    resource_name="test",
    id="asia-northeast1-a/clustername",
)

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

mikhailshilkov commented 1 year ago

I can repro this with

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

gcp.container.Cluster.get("test", "clustername", {
  location:"asia-northeast1-a",
});

Probably related to a read that doesn't find a cluster?

This looks like an upstream issue, the panic happens on this line: https://github.com/hashicorp/terraform-provider-google-beta/blob/66a274cf01fba417e2065f58aeda514542c56b4a/google-beta/services/container/resource_container_cluster.go#L2439

There are quite a few upstream issues that look similar: https://github.com/hashicorp/terraform-provider-google/issues?q=is%3Aissue+google_container_cluster+invalid+memory+address+or+nil+pointer+dereference Most are old and closed, but also this code hasn't changed since 2020...

I'm glad you have a workaround for now.

VenelinMartinov commented 2 months ago

This is likely caused by https://github.com/pulumi/pulumi-terraform-bridge/issues/2282