https://pulumi.com logo
Title
s

shy-mouse-88505

05/25/2022, 6:10 PM
Does somebody know what I'm doing wrong with
apply
?
const db = new aws.rds.Instance(`postgresdb-${stage}`, {
...
});

export const dbEndpoint = db.endpoint.apply((e) => `${e}`);
But I'm still getting an output
Outputs:
  + dbEndpoint : output<string>
c

clever-sunset-76585

05/25/2022, 6:21 PM
You don't need an
apply
with that output since you are not doing any string interpolation:
export const dbEndpoint = db.endpoint;
Did that not work for you for some reason?
s

shy-mouse-88505

05/25/2022, 6:34 PM
Yeah same thing
Outputs:
  + dbEndpoint : output<string>
I'm on
pulumi version
v3.33.1
c

clever-sunset-76585

05/25/2022, 6:36 PM
Are you looking at the
preview
phase? Because during preview, outputs will be unknown if the resource hadn't been created from a previous update phase.
s

shy-mouse-88505

05/25/2022, 6:37 PM
Yeah I'm looking at preview but actually the resource was created before (I was expecting a different output even in preview) but I can give a try in real. Thanks!
c

clever-sunset-76585

05/25/2022, 6:39 PM
Hmm if the RDS instance was created before in the same stack, then I would expect its endpoint to be known during subsequent preview phases. It's also possible that it's showing as
output<string>
here since the stack output property is new.
1
If your instance exists then the only thing that would change is the creation of the stack output property. In other words, the resource changes should show
x unchanged
, assuming you don't have any other resources that are changing.
s

shy-mouse-88505

05/26/2022, 12:26 AM
That's right, I get
Resources:
    18 unchanged
Still, I can't figure out the logic behind. On the real execution (same than in the preview)
export const POSTGRES_ENDPOINT = db.endpoint;
export const POSTGRES_PASSWORD = dbPassword;
export const postgresUrl = `postgresql://${dbUser}:${POSTGRES_PASSWORD}@${POSTGRES_ENDPOINT}/${dbName}?schema=public`;
export const POSTGRES_URL_APPLY = pulumi
  .all([db.endpoint, dbPassword])
  .apply(([endpoint, password]) => {
    console.log("This is e", endpoint, password);
    return `postgresql://${dbUser}:${password}@${endpoint}/${dbName}?schema=public`;
  });
I still can't figure out the logic of this, while endpoint and password are valid as long as we don't perform operations on them, the moment I want to put them into the URL I get the same error
POSTGRES_ENDPOINT : "<http://postgresdb-testxxx.xxx.us-east-1.rds.amazonaws.com:5432|postgresdb-testxxx.xxx.us-east-1.rds.amazonaws.com:5432>"
    POSTGRES_PASSWORD : [secret]
POSTGRES_URL_APPLY: "<postgresql://dbAppUser>:Calling [toString] on an [Output<T>] is not supported.\n\nTo get the value of an Output<T> as an Output<string> consider either:\n1: o.apply(v => `prefix${v}suffix`)\n2: pulumi.interpolate `prefix${v}suffix`\n\nSee <https://pulumi.io/help/outputs> for more details.\nThis function may throw in a future version of @pulumi/pulumi.@Calling [toString] on an [Output<T>] is not supported.\n\nTo get the value of an Output<T> as an Output<string> consider either:\n1: o.apply(v => `prefix${v}suffix`)\n2: pulumi.interpolate `prefix${v}suffix`\n\nSee <https://pulumi.io/help/outputs> for more details.\nThis function may throw in a future version of @pulumi/pulumi./dbtesting?schema=public" => [secret]
c

clever-sunset-76585

05/26/2022, 12:34 AM
If you want to use
Output<string>
in string interpolation, you should use
pulumi.interpolate
. It's a special function that understands how to resolve the
Output<T>
values to their
T
type. So like this:
export const postgresUrl = pulumi.interpolate `postgresql://${dbUser}:${POSTGRES_PASSWORD}@${POSTGRES_ENDPOINT}/${dbName}?schema=public`
Note that the return type of an interpolate itself is an
Output<string>
, which the Pulumi engine will know how to deal with. The problem with using regular JS interpolation is the output properties of resources you use inside the backticks are special. They are promise-like and Node will not know how to deal with them.
s

shy-mouse-88505

05/26/2022, 6:46 PM
Thanks @clever-sunset-76585, I think I'm starting to get this right. Makes sense, thanks again!