aws-architect 6.7.144 → 6.7.145
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -517,6 +517,47 @@ class CloudFormationDeployer {
|
|
|
517
517
|
await this.cloudFormationClient.createStackSet(stackParameters).promise();
|
|
518
518
|
}
|
|
519
519
|
|
|
520
|
+
const org = new Organizations({ region: 'us-east-1' });
|
|
521
|
+
const rootOrgsInfo = await org.listRoots({}).promise();
|
|
522
|
+
const rootOuIds = options.orgIds || rootOrgsInfo.Roots.map(root => root.Id);
|
|
523
|
+
|
|
524
|
+
try {
|
|
525
|
+
let allAccounts = [];
|
|
526
|
+
let nextToken;
|
|
527
|
+
do {
|
|
528
|
+
const response = await org.listAccounts({ NextToken: nextToken }).promise();
|
|
529
|
+
allAccounts.push(...response.Accounts);
|
|
530
|
+
nextToken = response.NextToken;
|
|
531
|
+
} while (nextToken);
|
|
532
|
+
|
|
533
|
+
const suspendedAccountIds = new Set(allAccounts.filter(a => a.Status === 'SUSPENDED' || a.Status === 'PENDING_CLOSURE').map(a => a.Id));
|
|
534
|
+
const existingInstances = await this.cloudFormationClient.listStackInstances({ StackSetName: options.stackSetName }).promise().then(d => d.Summaries);
|
|
535
|
+
const suspendedInstances = existingInstances.filter(s => suspendedAccountIds.has(s.Account));
|
|
536
|
+
const uniqueSuspendedAccounts = [...new Set(suspendedInstances.map(s => s.Account))];
|
|
537
|
+
|
|
538
|
+
if (uniqueSuspendedAccounts.length) {
|
|
539
|
+
const suspendedRegions = [...new Set(suspendedInstances.map(s => s.Region))];
|
|
540
|
+
console.log(`Removing stack instances from ${uniqueSuspendedAccounts.length} suspended accounts: ${uniqueSuspendedAccounts.join(', ')}`);
|
|
541
|
+
await this.cloudFormationClient.deleteStackInstances({
|
|
542
|
+
StackSetName: options.stackSetName,
|
|
543
|
+
DeploymentTargets: {
|
|
544
|
+
OrganizationalUnitIds: rootOuIds,
|
|
545
|
+
Accounts: uniqueSuspendedAccounts,
|
|
546
|
+
AccountFilterType: 'INTERSECTION'
|
|
547
|
+
},
|
|
548
|
+
Regions: suspendedRegions,
|
|
549
|
+
RetainStacks: true,
|
|
550
|
+
OperationPreferences: {
|
|
551
|
+
FailureToleranceCount: uniqueSuspendedAccounts.length,
|
|
552
|
+
MaxConcurrentCount: 20,
|
|
553
|
+
RegionConcurrencyType: 'PARALLEL'
|
|
554
|
+
}
|
|
555
|
+
}).promise();
|
|
556
|
+
}
|
|
557
|
+
} catch (error) {
|
|
558
|
+
console.log('Skipping removal of suspected account stackset, due to error:', error);
|
|
559
|
+
}
|
|
560
|
+
|
|
520
561
|
const currentStackData = await this.cloudFormationClient.describeStackSet({ StackSetName: options.stackSetName }).promise().then(data => data.StackSet);
|
|
521
562
|
const rawRegions = await new EC2().describeRegions().promise().then(data => data.Regions.map(r => r.RegionName));
|
|
522
563
|
const newRegions = rawRegions.filter(r => !currentStackData.Regions || !currentStackData.Regions.some(e => e === r))
|
|
@@ -548,12 +589,10 @@ class CloudFormationDeployer {
|
|
|
548
589
|
return { title: 'Success' };
|
|
549
590
|
}
|
|
550
591
|
|
|
551
|
-
const rootOrgsInfo = await new Organizations({ region: 'us-east-1' }).listRoots({}).promise();
|
|
552
|
-
|
|
553
592
|
const deployToAdditionalRegionsParams = {
|
|
554
593
|
StackSetName: options.stackSetName,
|
|
555
594
|
DeploymentTargets: {
|
|
556
|
-
OrganizationalUnitIds:
|
|
595
|
+
OrganizationalUnitIds: rootOuIds
|
|
557
596
|
},
|
|
558
597
|
Regions: newRegions,
|
|
559
598
|
OperationId: changeSetName,
|