https://pulumi.com logo
Title
h

hallowed-room-5599

02/27/2023, 1:03 PM
Due to Pulumi not playing well with GKE in Python I'm trying to do some workaround by directly calling
gcloud
but I'm lost and can't find much examples. With the code below I get
error: unrecognized resource type (Check): gcp:myaccount:Cluster
class MyCluster(pulumi.CustomResource):
    def __init__(self, name, opts=None):
        super().__init__("gcp:myaccount:Cluster", name, {}, opts)

    def create(self):
        # TODO: Call gcloud directly to create cluster
        super().create()

    def delete(self):
        # TODO: Call gcloud directly to kill cluster
        super().delete()


cluster = MyCluster("mycluster")
What is
*:**:**
supposed to be?
e

echoing-dinner-19531

02/27/2023, 3:13 PM
You should in general not be creating your own
CustomResource
, they are specific to providers. "gpc:myaccount:Cluster" tells the engine this is a resource from the "gcp" provider called "myaccount:Cluster". The gcp provider doesn't define that resource so you get an unrecognized resource type error.
h

hallowed-room-5599

02/27/2023, 3:16 PM
Well I need a workaround, to call directly
gcloud
. So what is the suggested approach? I'm on a GKE trial period so can't be waiting for Pulumi to maybe or maybe not implement the missing gcloud flag
e

echoing-dinner-19531

02/27/2023, 3:16 PM
The normal workaround would be to use dynamic providers: https://www.pulumi.com/docs/intro/concepts/resources/dynamic-providers/
h

hallowed-room-5599

02/27/2023, 4:34 PM
Thanks. Unfortunately it's very hard to develop with Python since breakpoints don't work and the examples go from too simple to too complex Any ideas how to just get the
cluster.name
below without adding GkeClusterArgs and a bunch of unnecessary boilerplate?
class GkeClusterProvider(ResourceProvider):
    def create(self, inputs):
        cluster_name = inputs["name"] + "-" + str(uuid.uuid4())[:8]
        return CreateResult(id_=cluster_name, outs={
            "name": cluster_name,
        })

class GkeCluster(Resource):
    name: pulumi.Output[str]
    def __init__(self, name, props=None, opts=None):
        props = props or {}
        super().__init__(GkeClusterProvider(), name, {}, opts)

cluster = GkeCluster("cluster-staging")
pulumi.export("myresource", cluster.name)
e

echoing-dinner-19531

02/27/2023, 5:46 PM
Add "name"=None to props in the GkeCluster init method, and pass props to the super init