sparse-intern-71089
11/09/2023, 5:33 PMcuddly-computer-18851
11/09/2023, 11:19 PMasync function waitForInstanceRefresh(name: string): Promise<boolean> {
if (!pulumi.runtime.isDryRun()) {
const credentials = fromNodeProviderChain({ profile: awsProfile });
const config = { credentials, region: awsRegion };
const autoScalingClient = new AutoScalingClient(config);
const refreshCommand = new DescribeInstanceRefreshesCommand({
AutoScalingGroupName: name,
MaxRecords: 100,
});
await backOff(
async () => {
const { InstanceRefreshes } = await autoScalingClient.send(refreshCommand);
const inProgress = InstanceRefreshes?.filter((e) => e.Status === 'InProgress');
if (inProgress && inProgress.length === 0) {
return true;
} else if (inProgress) {
throw Error(`ASG refresh still in progress`);
} else {
throw Error('ASG client failed?');
}
},
{
retry: async (e, attemptNumber) => {
await <http://pulumi.log.info|pulumi.log.info>(`checking ASG refresh for ${name}: ${attemptNumber}`);
return true;
},
numOfAttempts: 30,
startingDelay: 10000,
maxDelay: 60000,
delayFirstAttempt: true,
jitter: 'none',
},
);
}
return true;
}
then call this in an apply
on some property before the thing you want to deploy, like
asg.name.apply((name) => waitForInstanceRefresh(name));