Search code examples
typescriptgoogle-cloud-platformdevopsinfrastructure-as-codepulumi

How to set an specific entrypoint to a google cloud function with pulumi


Currently I'm starting with pulumi as a IaC tool, also I'm working with TypeScript. For a google cloud function with HTTP Trigger, Does anybody know How can I set the urn with a specific name? I'm creating a new Function as code below.

I'm using as refence the code from: https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/gcp/cloudfunctions

This is my code:

const functionArchives = new gcp.storage.BucketObject("functionName", {
    bucket: bucket.name,
    source: new pulumi.asset.AssetArchive({
        ".": new pulumi.asset.FileArchive("./path"),
    }),
});
const myFunction = new gcp.cloudfunctions.Function("functionName", {
    availableMemoryMb: 128,
    description: "Description",
    entryPoint: "functionName",
    environmentVariables: envVariables,
    labels: {
        "key": "val"
    },
    runtime: "nodejs8",
    sourceArchiveBucket: bucket.name,
    sourceArchiveObject: functionArchives.name,
    timeout: 60,
    triggerHttp: true,
});

Butt that code always create the urn with some characters added at the end of the string that I originally set. i.e.:

https://<region-projectname>.cloudfunctions.net/functionName-43db05f

I would like that the urn to be

https://<region-projectname>.cloudfunctions.net/functionName


Solution

  • You can do so by passing a name argument to the Function constructor:

    const myFunction = new gcp.cloudfunctions.Function("functionName", {
        // ... other args
        name: "functionName",
        // ... other args
    });
    

    By default, Pulumi appends a unique code to all names. From https://www.pulumi.com/docs/reference/programming-model/#autonaming:

    This random postfix is added by default for two reasons. First, it ensures that two instances of a program can be deployed to the same environment without risk of name collisions. Second, it ensures that it will be possible to do zero-downtime replacements when needed, by creating the new resource first, updating any references to point to it, and then deleting the old resource.

    This behavior can be overridden per resource by explicitly setting a name property on the resource.