Hi I am trying to export outputs from resources cr...
# general
Hi I am trying to export outputs from resources created inside a loop using typescript. However the accountOutput is always empty. I am wondering whats the right approach to do this.
Copy code
let accountDetails = [
    {name: 'test', email: '<mailto:testt@example.io|testt@example.io>', environment: 'test', billingInfoAccess: 'ALLOW'}

var accountOutput: { accountName: string, accountId: string }[] = [];

for (const accountDetail of accountDetails) {
    const account = new aws.organizations.Account(accountDetail.name, {
        email: accountDetail.email,
        iamUserAccessToBilling: accountDetail.billingInfoAccess,
        name: accountDetail.name,
        tags: {
            Environment: accountDetail.environment

    account.arn.apply(arn => {
        accountOutput.push({accountName: accountDetail.name, accountId: arn})

export const outputs = {
    accountInfo: accountOutput,
"applys" run asynchronously trying to do data mutations in them is fraught with issues. Flip the apply and push around:
Copy code
accountOutput.push(account.arn.apply(arn => {accountName: accountDetail.name, accountId: arn}))
🙌 1