普鲁米确保依赖顺序

Posted

技术标签:

【中文标题】普鲁米确保依赖顺序【英文标题】:Pulumi ensure dependency order 【发布时间】:2022-01-11 12:04:38 【问题描述】:

在我制定 OpenAPI 规范之前,我需要一种方法来确保某些服务已经建立起来,并且它们的 URL 已在 GCP 中正式化 - 使用替换。 URL 相对动态,因为这种环境每晚都会被拆除。

我有一个解决方案是

import  helloWorldUrl  from './cloud-run/hello-world';
import  anotherHelloWorldUrl  from './cloud-run/another-hello-world-service';
import * as pulumi from '@pulumi/pulumi';
import * as fs from 'fs';
import * as Mustache from 'mustache';

pulumi.all([helloWorldUrl, anotherHelloWorldUrl])
    .apply(([hello, another]) => 
        let gatewayOpenAPI = fs.readFileSync('./api-gateway/open-api/gateway.yaml').toString();
        gatewayOpenAPI = Mustache.render(gatewayOpenAPI,  helloWorldUrl: hello, anotherHelloWorld: another );
        fs.writeFileSync(`./api-gateway/open-api/gateway-$pulumi.getStack().yaml`, gatewayOpenAPI);

      // create api gateway infra here.

      // cannot return outputs here :(
    );

但这不允许我设置输出。有没有更优雅的解决方案?

干杯 KH

【问题讨论】:

【参考方案1】:

如果你想有一个严格的依赖顺序,你应该使用Pulumi Component Resources。然后,您可以将 URL 作为输入传递给组件资源,并访问由该组件资源创建的任何输出。您还应该注意,在applymethod的回调中不允许创建任何资源。

您可能会发现以下示例有助于查看正在运行的组件资源:https://www.pulumi.com/registry/packages/aws/how-to-guides/s3-folder-component/

【讨论】:

以上是关于普鲁米确保依赖顺序的主要内容,如果未能解决你的问题,请参考以下文章

phpunit跳过具有不同测试用例之间依赖关系的测试

如何确保在 systemd 中启动服务之前存在延迟?

MSBuild 在 _CopyOutOfDateSourceItemsToOutputDirectory 期间复制依赖项目文件

seaJS简介和完整实例

seaJS简介和完整实例

requireJS简介和一个完整实例