0

目前我开始使用 pulumi 作为 IaC 工具,同时我也在使用 TypeScript。对于带有 HTTP 触发器的谷歌云功能,有人知道如何设置具有特定名称的骨灰盒吗?我正在创建一个新函数,如下所示。

我使用以下代码作为参考:https ://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/gcp/cloudfunctions

这是我的代码:

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,
});

对接该代码总是在我最初设置的字符串的末尾添加一些字符来创建骨灰盒。IE:

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

我想要那个骨灰盒

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

4

1 回答 1

1

您可以通过将name参数传递给Function构造函数来做到这一点:

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.

于 2019-08-05T19:26:04.400 回答