Is there a better way to do this? I want to take t...
# typescript
f
Is there a better way to do this? I want to take the output from another stack (
rootAccountId
) and use it when creating the principal for a role.
Copy code
const rootAccountId = organization.getOutput('rootAccountId'); <-- output from another stack

const adminRole = createRole({
  allowedActions: accountRoles.admin,
  principal: {
    AWS: [rootAccountId.apply((id) => `arn:aws:iam::${id}:root`)],
  },
  roleName: 'admin',
});

export function createRole({
  allowedActions,
  principal,
  roleName,
}: {
  allowedActions: string[];
  principal: aws.iam.Principal;
  roleName: string;
}) {
  const role = new aws.iam.Role(`${roleName}-role`, {
    assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal(principal),
  });
  ...
}