Search code examples
typescriptpulumi

How do I log a value in Pulumi?


Per Pulumi's documentation for inputs and outputs I am attempting to console.log() a string value of an output.

console.log(
  `>>> masterUsername`,
  rdsCluster.masterUsername.apply((v) => `swag${v}swag`)
);

returns

    >>> masterUsername OutputImpl {
      __pulumiOutput: true,
      resources: [Function (anonymous)],
      allResources: [Function (anonymous)],
      isKnown: Promise { <pending> },
      isSecret: Promise { <pending> },
      promise: [Function (anonymous)],
      toString: [Function (anonymous)],
      toJSON: [Function (anonymous)]
    }

I am running o.apply(v => `prefix${v}suffix`) as specified.

How can I log a value from Pulumi?


Solution

  • You should do it the other way around:

    rdsCluster.masterUsername.apply(v =>
      console.log(`>>> masterUsername`, `swag${v}swag`));
    

    The callback will run when the output value is resolved and will print the value at that time. In preview, it may not run at all if the value isn't known.