https://pulumi.com logo
#typescript
Title
# typescript
l

loud-bear-51491

10/06/2021, 4:16 PM
Hi.. I am trying to run a piece of code to create a group when account id of aws is xxx and i get an error on my ci saying
infra/groups.ts(6,14): error TS2322: Type 'Promise<string>' is not assignable to type 'string'.
here is the code
Copy code
const current = aws.getCallerIdentity({});
export const accountId: string = current.then(current => current.accountId);

if (accountId == "xxx") { 

const devops = new aws.iam.Group("devops", {
    name: "devops-users",
    path: "/",
});

}
s

steep-toddler-94095

10/06/2021, 4:47 PM
Like the error message says,
accountId
is a
Promise<string>
so you can't so a comparison with a
string
in your
if
. You'll need to do this comparison in a context where the promise is unwrapped, either within a
.then
or after the variable is `await`ed
1
l

little-cartoon-10569

10/06/2021, 9:33 PM
Often the best thing to do is to avoid this sort of issue. For example, perhaps you can infer whether or not to create the group from the stack instead of from the caller identity?
pulumi.getStack()
returns a simple string.
👍 2