https://pulumi.com logo
Title
b

bland-pharmacist-96854

02/01/2023, 6:49 PM
What about this, I'm trying to get the AWS account ID inside an asumePolicy but I'm struggling with .then and promises
s

steep-toddler-94095

02/01/2023, 7:34 PM
accountId is a
Promise
so you can't just do string concat on it and expect it to work. Pulumi has an
interpolate
function though that you can use for something like this: `interpolate`system😒erviceaccount:emr:emr-containers-sa---${accountId}-${jobExecutionRoleNameBase36Encoded}``
b

bland-pharmacist-96854

02/01/2023, 7:37 PM
then, should I keep
then
also?
Can you provide an example, please?
s

steep-toddler-94095

02/01/2023, 7:42 PM
the example is in my message. it's meant to replace this code in your snippet
"system:serviceaccount:emr:emr-containers-sa-*-*-" +
                    accountId +
                    "-" +
                    jobExecutionRoleNameBase36Encoded
b

bland-pharmacist-96854

02/01/2023, 7:47 PM
ok, it works, how I can split into multiple lines that?
ah with
pulumi.concat
o

orange-policeman-59119

02/02/2023, 2:39 AM
It's not widely used, but in TypeScript template strings using ``like-${this}`` can be prefixed by a function that can handle them in a special way. Pulumi provides one for string interpolation that works with promises and outputs:
const foo = pulumi.interpolate`this text is in a template expression, the variable foo is an Output<string>, and this template can handle promises and outputs like: ${accountId}`;
The catch is that like with promises, once a value is an "Output", it stays in the world of Output<T> values forever. e.g.:
const bar = foo.apply(str => str.length());
bar
should now be an Output<number>, and it can be passed to Pulumi resources.