Hi, I have question regarding handling null values...
# contribute
b
Hi, I have question regarding handling null values in preview. Code like this:
Copy code
import * as docker from "@pulumi/docker";

const ubuntu = new docker.RemoteImage("ubuntu", {
    name: "ubuntu:precise"
});

const val = ubuntu.build.apply(_ => "ubuntu:precise")

const ubuntu2 = new docker.RemoteImage("ubuntu2", {
    name: val
});
works not as expected. Because build is null, during preview name of the second ubuntu will be always unknown. Are there any tickets regarding making
null
and
notyetcomputed
values different during preview? That code above ends with infinite cycle where there is one value to replace during preview that is untouched during actual run:
Copy code
Enter your passphrase to unlock config/secrets
Previewing update (dev):
     Type                         Name                Plan        Info
     pulumi:pulumi:Stack          pulumi-ts-test-dev
 +-  └─ docker:index:RemoteImage  ubuntu2             replace     [diff: ~name]
Resources:
    +-1 to replace
    2 unchanged

Do you want to perform this update? yes
Updating (dev):
     Type                 Name                Status
     pulumi:pulumi:Stack  pulumi-ts-test-dev
Resources:
    3 unchanged

Duration: 2s
l
There seems to be a few misunderstandings about how to use the Docker provider in this code.
RemoteImage.build
is an input, it's used for passing command line parameters to the Docker CLI. Calling
apply
on it is using it as an output: you're looking up what values were passed to the CLI back when it was called. You're then taking the object containing all those parameters, ignoring it, and returning the value "ubuntu:precise". So
val
will always be an Output wrapping "ubuntu:precise". That's essentially hard-coded. What is it that you are hoping to do, and I'll help you write code that does that.
b
I'm writing support for new language and I can't figure out how Pulumi differentiates between
notyetcomputed
and
null
values during preview (grpc server just seems to return nothing - as in struct field does not exist at all - in both cases). From this examples it seems that official languages also cannot differentiate - during preview all nulls become
notyetcomputed
values. I found example that use only outputs:
Copy code
import * as docker from "@pulumi/docker";

const container = new docker.Container("cont", {
    image: "sha256:e4c58958181a5925816faa528ce959e487632f4cfd192f8132f71b32df2744b4",
    networkMode: "bridge",
    command: ["sleep", "10000"],
})

const val = container.containerLogs.apply(_ => "ubuntu:precise")

const ubuntu2 = new docker.RemoteImage("ubuntu2", {
    name: val
});
Copy code
Previewing update (dev):
     Type                         Name                Plan        Info
     pulumi:pulumi:Stack          pulumi-ts-test-dev
 +-  └─ docker:index:RemoteImage  ubuntu2             replace     [diff: ~name]
Resources:
    +-1 to replace
    2 unchanged

Do you want to perform this update? yes
Updating (dev):
     Type                 Name                Status
     pulumi:pulumi:Stack  pulumi-ts-test-dev
Resources:
    3 unchanged

Duration: 2s
l
Yes, that's fine. Applied outputs in preview are defined to be not known. If you want to tell the difference, you can check if you're in preview from the pulumi.runtime object.
Check the
isDryRun
property.