Is it possible to add a custom resource to an exis...
# general
m
Is it possible to add a custom resource to an existing provider? I want to make a custom resource that invokes a GCP CloudRun service, and uses the same credentials as the existing provider?
g
Yes, this is a classic use case for Pulumi's Dynamic Providers. You can't modify the existing
pulumi-gcp
provider itself. However, you can create a custom resource type using a Dynamic Provider that runs your arbitrary code during
pulumi up
. This code can use the standard GCP SDKs, which will automatically pick up the same credentials that the main
pulumi-gcp
provider uses (e.g., from Application Default Credentials, environment variables like
GOOGLE_APPLICATION_CREDENTIALS
, or gcloud CLI configuration). Alternatively on the credential front, you could declare an Explicit Provider and pass that into resourceOptions.
Copy code
import * as gcp from "@pulumi/gcp";

// Assume you have a provider instance:
const myProvider = new gcp.Provider("myProvider", {
    credentials: "...",
    project: "...",
    region: "...",
});

// When creating a resource:
const myResource = new gcp.cloudrun.Service("myService", {
    // ... resource args ...
}, { provider: myProvider });