Search code examples
typescriptkubernetesinfrastructure-as-codepulumi

In Pulumi, exist a equivalent to pulumi.Output.apply, but to transform pulumi.Input values?


I'm developing a Pulumi ComponentResource named CopyPostgresql in Typescript.

CopyPostgreSql is a Kubernetes job that copy in streaming the content of a source Postgresql database to a target Postgresql database. The options of CopyPostgreSql include properties source and target. Both are of type DatabaseInput.

export interface DatabaseInput {
    readonly port: Input<number>;
    readonly user: Input<string>;
    readonly password: Input<string>;
    readonly host: Input<string>;
    readonly dbname: Input<string>;
}

So, i want to use port as value of another property from another component, but that another property is of type Input< string >.

How can i apply (or transform) a value of type Input< number > to Input< string >? and in general: In Pulumi, exist a equivalent to pulumi.Output.apply, but to transform pulumi.Input values?


Solution

  • You can do pulumi.output(inputValue).apply(f).

    So, you can flow them back and forth:

    const input1: pulumi.Input<string> = "hi";
    const output1 = pulumi.output(input1);
    const output2 = output1.apply(s => s.toUpperCase());
    const input2: pulumi.Input<string> = output2;