pulumi / pulumi-java

Java support for Pulumi
Apache License 2.0
69 stars 21 forks source link

Permit user programs that decide on stack outputs in a Future #660

Open t0yv0 opened 2 years ago

t0yv0 commented 2 years ago

Hello!

Issue details

Current signature Pulumi.run assumes that the program will immediately register the stack outputs:

        Pulumi.run(ctx -> {
            ctx.export("a", Output.of(1));
        });

What if the program does not know what the set of stack outputs is going to be until some CompletableFuture? The awkward workaround right now is to force (join) the Future inside the Pulumi program:

        CompletableFuture<String> xname;
        Pulumi.run(ctx -> {
            var x = xname.join();
            ctx.export(x, Output.of(1));
        });

It would be nice to allow deferring that without blocking a thread. Perhaps Pulumi.run(Function<Context,CompletableFuture<Void>>) overload to let the user program signal to the framework that it has some work to do.

I believe underlying framework supports this just fine, but we do not expose this capability to the user at the moment.

Not sure how useful this is in practice, but logging for posterity.

Affected area/feature

pawelprazak commented 2 years ago

Should be quite easy to achieve, if we decide to expose this kind of API.

Adding an overload to the DefaultRunner and an overloaded run and runAsync should do it from top of my head.

Internally, changing this:

public <T> CompletableFuture<Result<T>> runAsync(Supplier<T> callback) {
            var valueFuture = CompletableFuture.supplyAsync(callback);
            ...

into:

public <T> CompletableFuture<Result<T>> runAsync(CompletableFuture<Supplier<T>> callback) {
            ...

in the DefaultRunner would allow for this API to be added.