pulumi / pulumi-gcp

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

Provide a way to modify `location` in `CallbackFunction` #672

Open shishkin opened 2 years ago

shishkin commented 2 years ago

Hello!

Issue details

Topic callback function creates a storage bucket in a location different from default and there is no obvious API to override it.

Steps to reproduce

const gConf = new pulumi.Config("gcp");
const region = gConf.require("region"); // europe-west3

export const timeTriggerTopic = new gcp.pubsub.Topic("time-trigger");

export const onTimeTrigger = timeTriggerTopic.onMessagePublished("onTimeTrigger", {
  runtime: "nodejs16",
  region: region,
  callback: (event) => {
    console.log("doing something...");
  },
});

Expected:

Cloud function storage bucket created in europe-west3.

Actual:

    + gcp:pubsub/topic:Topic: (create)
        [urn=urn:pulumi:test::proj::gcp:pubsub/topic:Topic::time-trigger]
        [provider=urn:pulumi:test::proj::pulumi:providers:gcp::default_5_25_0::04da6b54-80e4-46f7-96ec-b56ff0331ba9]
        name: "time-trigger-e013984"
        + gcp:cloudfunctions:CallbackFunction: (create)
            [urn=urn:pulumi:test::proj::gcp:pubsub/topic:Topic$gcp:cloudfunctions:CallbackFunction::onTimeTrigger]
            + gcp:storage/bucket:Bucket: (create)
                [urn=urn:pulumi:test::proj::gcp:pubsub/topic:Topic$gcp:cloudfunctions:CallbackFunction$gcp:storage/bucket:Bucket::ontimetrigger]
                [provider=urn:pulumi:test::proj::pulumi:providers:gcp::default_5_25_0::04da6b54-80e4-46f7-96ec-b56ff0331ba9]
                forceDestroy: false
                location    : "US"
                name        : "ontimetrigger-4362d98"
                storageClass: "STANDARD"
leezen commented 2 years ago

You can override this using transformations

You can also optionally specify your own bucket when creating the callback.

leezen commented 2 years ago

I've updated this issue to reflect the enhancement necessary here, which is to have a way to plumb location through to the underlying Bucket in https://github.com/pulumi/pulumi-gcp/blob/master/sdk/nodejs/cloudfunctions/zMixins.ts#L147

shishkin commented 2 years ago

Thanks @leezen! I haven't look into transformations yet.

I somehow expected location affinity for all resources in a stack unless overridden. Would that make sense?

leezen commented 2 years ago

@shishkin Yes, that would make sense in contexts like the mixins as well and not trying to specify the default multi-region US