Search code examples
c#pulumi

How to print specific values to CLI upon invocation of `pulumi up`?


When I invoke pulumi up, I want it to print as part its output - the public IP of the Pulumi.Aws.Ec2.Instance (e.g. Public IP: 1.2.3.4).

I have this code:

var server = new Instance("auto_mc_server", new InstanceArgs {
    InstanceType = "t2.micro",
    // ... more stuff ...
});

I see many questions asking about Outputs, so I tried for instance:

  1. Output.Format($"Public IP: {server.PublicIp}");
  2. Output.Create("public_ip").Apply(s => $"Public IP: {server.PublicIp}");

... and other variations ...

But nothing gets printed upon pulumi up...


Solution

  • You need to return a value in the C# SDK

    return new Dictionary<string, object?>
    {
       ["publicIp"] = server.PublicIp
    };