What about this, I'm trying to get the AWS account...
# typescript
b
What about this, I'm trying to get the AWS account ID inside an asumePolicy but I'm struggling with .then and promises
s
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`systemserviceaccountemr:emr-containers-sa---${accountId}-${jobExecutionRoleNameBase36Encoded}``
b
then, should I keep
then
also?
Can you provide an example, please?
s
the example is in my message. it's meant to replace this code in your snippet
Copy code
"system:serviceaccount:emr:emr-containers-sa-*-*-" +
                    accountId +
                    "-" +
                    jobExecutionRoleNameBase36Encoded
b
ok, it works, how I can split into multiple lines that?
ah with
pulumi.concat
o
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:
Copy code
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.:
Copy code
const bar = foo.apply(str => str.length());
bar
should now be an Output<number>, and it can be passed to Pulumi resources.