sparse-intern-71089
11/14/2023, 9:05 PMfreezing-electrician-6256
11/14/2023, 9:06 PMfreezing-electrician-6256
11/14/2023, 9:10 PM[null]
right away, which makes me think that it's not waiting to compute the value until it's neededdry-keyboard-94795
11/14/2023, 9:34 PMgetRole
, and keep retrying until you end up with a non-null response.
Let me setup an environment so I can provide an example quicklydry-keyboard-94795
11/14/2023, 9:37 PMgetRolesOutput
usage, which will help with doing an example heredry-keyboard-94795
11/14/2023, 10:08 PMasync function getRoleAsync(nameRegex: string): Promise<aws.iam.GetRoleResult> {
let roleName: string | null = null;
const maxRetries = 10;
let attempts = 0;
const sleepTime = 1000;
do {
attempts++;
let rolesResult = await aws.iam.getRoles({
nameRegex: nameRegex,
});
if (rolesResult.names.length > 0) {
roleName = rolesResult.names[0];
}
if (roleName == null) {
console.log("retrying!", rolesResult);
await new Promise(r => setTimeout(r, sleepTime));
}
} while (roleName == null && attempts < maxRetries);
if (roleName == null) {
throw new Error("Failed to find role");
}
return aws.iam.getRole({
name: roleName,
});
}
// These are for demo purposes to show how to unrole a promise in Pulumi
const roleDependingOnResource = stubResource.id.apply(_ => getRoleAsync("NEVER_EXISTS"));
const roleNonDependent = pulumi.output(getRoleAsync("NEVER_EXISTS"));
dry-keyboard-94795
11/14/2023, 10:16 PMimport { retryDecorator } from "ts-retry-promise";
const getRole = (nameRegex: string) => aws.iam.getRoles({
nameRegex: nameRegex,
}).then(roles => {
if (roles.names.length <= 0) {
throw new Error("Failed to find role");
}
return aws.iam.getRole({
name: roles.names[0],
});
});
const retryGetRole = retryDecorator(getRole, { retries: 10, delay: 1000 });
// These are for demo purposes to show how to unrole a promise in Pulumi
const roleDependingOnResource = stubResource.id.apply(_ => retryGetRole("NEVER_EXISTS"));
const roleNonDependent = pulumi.output(retryGetRole("NEVER_EXISTS"));
freezing-electrician-6256
11/14/2023, 11:07 PMpolicy: pulumi.jsonStringify({
Version: "2012-10-17",
Statement: [
{
Sid: "Foo",
Effect: "Allow",
Principal: {
AWS: [
aws.iam.getRoleOutput(params),
]
},
(the getRoleOutput is technically wrapped in a function but effectively ends up like that)freezing-electrician-6256
11/14/2023, 11:08 PM