shy-mouse-88505
05/25/2022, 6:10 PMapply
?
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>
clever-sunset-76585
05/25/2022, 6:21 PMapply
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?shy-mouse-88505
05/25/2022, 6:34 PMOutputs:
+ dbEndpoint : output<string>
pulumi version
v3.33.1
clever-sunset-76585
05/25/2022, 6:36 PMpreview
phase? Because during preview, outputs will be unknown if the resource hadn't been created from a previous update phase.shy-mouse-88505
05/25/2022, 6:37 PMclever-sunset-76585
05/25/2022, 6:39 PMoutput<string>
here since the stack output property is new.x unchanged
, assuming you don't have any other resources that are changing.shy-mouse-88505
05/26/2022, 12:26 AMResources:
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]
clever-sunset-76585
05/26/2022, 12:34 AMOutput<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.shy-mouse-88505
05/26/2022, 6:46 PM