gifted-gigabyte-53859
04/01/2025, 3:17 AMgroupname:
- userA
- userB
group2:
- userA
- userC
etc
This was not convenient to do in yaml as I'd have 30+ permutations in just a simple setup of 10 groups with 3 users each.
So I made a dynamic loop to do it in typescript.
However now I want to reference a particular user as a stack output in another program.
E.g. I want to add 'userA' in an IAM policy on a particular resource.
Given that I don't have static user resources, how would I reference a user as an output in another program?little-cartoon-10569
04/01/2025, 3:48 AMgifted-gigabyte-53859
04/01/2025, 3:56 AM//inside my loop - I've redacted all the stuff above
// Store the userId in the users object, keyed by username
users[username] = user.apply(u => u.userId);
});
});
// At the end of the program, outside the loop
// Export the users object
export const users = users;
In my other yaml program, I'd then reference the users like this:
variables:
varKeyAdmins: '[
"${typescriptProject.users["james"]}",
"${typescriptProject.users["bruce"]}",
]'
Method 2:
//inside my loop - I've redacted all the stuff above
// Store the userId in the users object, using a normalized key (e.g., "userJames")
const userKey = `user${username.split("@")[0]}`; // e.g., "userJames" from "james@example.com"
users[userKey] = user.apply(u => u.userId);
});
});
// At the end of the program, outside the loop
// Export individual users dynamically
Object.keys(users).forEach(key => {
(exports as any)[key] = users[key];
});
In my other program (yaml), I'd then reference the users like this:
In my other yaml program, I'd then reference the users like this:
variables:
varKeyAdmins: '[
"${typescriptProject.userJames}",
"${typescriptProject.userBruce}",
]'
gifted-gigabyte-53859
04/01/2025, 4:16 AMlittle-cartoon-10569
04/01/2025, 4:30 AMlittle-cartoon-10569
04/01/2025, 4:32 AMusers[username] = user.apply(u => u.userId);
In this case, you'd use
userIds[index] = user.id
little-cartoon-10569
04/01/2025, 4:32 AMapply()
can and should be avoided. It's needed in some tricky cases, but most of the time, you can dereference outputs just fine.gifted-gigabyte-53859
04/01/2025, 5:20 AMgifted-gigabyte-53859
04/01/2025, 6:17 AMuserIds[index] = user.id
doesn't seem to work in this particular case.
Possibly my AI generated code further up has done something unnecessary making this apply
required.
Anyway I got it sorted, thanks.