KnowHoper
KnowHoper

Reputation: 4622

Pulumi ensure dependency order

I need a way of ensuring some services have been stood up and their URLs formalised in GCP before I craft an OpenAPI spec - using substitutions. The URLs are relatively dynamic as this environment is torn down nightly.

One solution I have is

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 :(
    });

but this does not allow me to set Outputs. Is there a more elegant solution to this?

Cheers KH

Upvotes: 4

Views: 913

Answers (1)

user3099576
user3099576

Reputation:

If you want to have a strict dependency order, you should use Pulumi Component Resources. You can then pass in your URLs as an input to the component resource, and access any outputs created by this component resource. You should also note that it's not allowed to create any resources in the callback of the apply method.

You might find the following example helpful to see the component resources in action: https://www.pulumi.com/registry/packages/aws/how-to-guides/s3-folder-component/

Upvotes: 1

Related Questions