Skip to content

Commit ae631c4

Browse files
fix(core): fix upgrade to v1.2.1 from v1.2.0 (#423)
* fixed issue while doing upgrade to 1.2.1 from 1.2.0 * fixed error while reading log archive central bucket * fixed test issues
1 parent 4d08975 commit ae631c4

File tree

3 files changed

+27
-34
lines changed

3 files changed

+27
-34
lines changed

src/deployments/cdk/src/deployments/cleanup/step-1.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AccountStacks } from '../../common/account-stacks';
33
import { StackOutput } from '@aws-accelerator/common-outputs/src/stack-output';
44
import { IamRoleOutputFinder } from '@aws-accelerator/common-outputs/src/iam-role';
55
import { ResourceCleanup } from '@aws-accelerator/custom-resource-cleanup';
6-
import { AccountBucketOutput } from '../defaults';
6+
import { AccountBucketOutputFinder } from '../defaults';
77
import { Account } from '../../utils/accounts';
88
import { ResourceCleanupOutputFinder } from './outputs';
99

@@ -33,40 +33,39 @@ export async function step1(props: VpcFlowLogsBucketPermissionsCleanupProps) {
3333
return;
3434
}
3535

36-
// Find the account default buckets in the outputs
37-
const accountBuckets = AccountBucketOutput.getAccountBuckets({
38-
accounts,
39-
accountStacks,
40-
config,
41-
outputs,
42-
});
43-
44-
const logArchiveAccount = config['global-options']['central-log-services'].account;
4536
const securityAccount = config['global-options']['central-security-services'].account;
46-
for (const accountKey of Object.keys(accountBuckets)) {
37+
for (const account of accounts) {
38+
const accountBucket = AccountBucketOutputFinder.tryFindOneByName({
39+
outputs,
40+
accountKey: account.key,
41+
});
42+
if (!accountBucket) {
43+
continue;
44+
}
45+
4746
// Skip deletion of Log Archive and Security account default bucket policy
48-
if (logArchiveAccount === accountKey || securityAccount === accountKey) {
49-
console.log(`Skipping the deletion of bucket policy for account ${accountKey}`);
47+
if (securityAccount === account.key) {
48+
console.log(`Skipping the deletion of bucket policy for account ${account.key}`);
5049
continue;
5150
}
5251

5352
const cleanupRoleOutput = IamRoleOutputFinder.tryFindOneByName({
5453
outputs,
55-
accountKey,
54+
accountKey: account.key,
5655
roleKey: 'ResourceCleanupRole',
5756
});
5857
if (!cleanupRoleOutput) {
5958
continue;
6059
}
6160

62-
const accountStack = accountStacks.tryGetOrCreateAccountStack(accountKey);
61+
const accountStack = accountStacks.tryGetOrCreateAccountStack(account.key);
6362
if (!accountStack) {
64-
console.warn(`Cannot find account stack ${accountKey}`);
63+
console.warn(`Cannot find account stack ${account.key}`);
6564
continue;
6665
}
6766

68-
new ResourceCleanup(accountStack, `BucketPolicyCleanup${accountKey}`, {
69-
bucketName: accountBuckets[accountKey].bucketName,
67+
new ResourceCleanup(accountStack, `BucketPolicyCleanup${account.key}`, {
68+
bucketName: accountBucket.bucketName,
7069
roleArn: cleanupRoleOutput.roleArn,
7170
});
7271
}

src/deployments/cdk/src/deployments/defaults/outputs.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { StructuredOutput, createCfnStructuredOutput } from '../../common/struct
1010
import { EbsKmsOutput } from '@aws-accelerator/common-outputs/src/ebs';
1111
import { SsmKmsOutput } from '@aws-accelerator/common-outputs/src/ssm';
1212
import { optional } from '@aws-accelerator/common-types';
13+
import { createStructuredOutputFinder } from '@aws-accelerator/common-outputs/src/structured-output';
1314

1415
export const CfnEbsKmsOutput = createCfnStructuredOutput(EbsKmsOutput);
1516

@@ -96,6 +97,15 @@ export const CfnLogBucketOutput = createCfnStructuredOutput(LogBucketOutputType)
9697
export const CfnCentralBucketOutput = createCfnStructuredOutput(CentralBucketOutputType);
9798
export const CfnAesBucketOutput = createCfnStructuredOutput(AesBucketOutputType);
9899

100+
export const AccountBucketOutputFinder = createStructuredOutputFinder(AccountBucketOutputType, finder => ({
101+
tryFindOneByName: (props: { outputs: StackOutput[]; accountKey?: string; region?: string }) =>
102+
finder.tryFindOne({
103+
outputs: props.outputs,
104+
accountKey: props.accountKey,
105+
region: props.region,
106+
}),
107+
}));
108+
99109
export namespace AccountBucketOutput {
100110
/**
101111
* Helper method to import the account buckets from different phases. It includes the log bucket.

src/deployments/cdk/test/apps/__snapshots__/unsupported-changed.spec.ts.snap

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,6 @@ exports[`there should not be any unsupported resource changes for AWS::Budgets::
630630

631631
exports[`there should not be any unsupported resource changes for AWS::Budgets::Budget: SharedNetworkPhase3 1`] = `Array []`;
632632

633-
exports[`there should not be any unsupported resource changes for AWS::Budgets::Budget: SharedServicesPhase0 1`] = `Array []`;
634-
635633
exports[`there should not be any unsupported resource changes for AWS::Budgets::Budget: SharedServicesPhase1 1`] = `Array []`;
636634

637635
exports[`there should not be any unsupported resource changes for AWS::Budgets::Budget: SharedServicesPhase2 1`] = `Array []`;
@@ -775,8 +773,6 @@ exports[`there should not be any unsupported resource changes for AWS::Directory
775773

776774
exports[`there should not be any unsupported resource changes for AWS::DirectoryService::MicrosoftAD: SharedNetworkPhase3 1`] = `Array []`;
777775

778-
exports[`there should not be any unsupported resource changes for AWS::DirectoryService::MicrosoftAD: SharedServicesPhase0 1`] = `Array []`;
779-
780776
exports[`there should not be any unsupported resource changes for AWS::DirectoryService::MicrosoftAD: SharedServicesPhase1 1`] = `Array []`;
781777

782778
exports[`there should not be any unsupported resource changes for AWS::DirectoryService::MicrosoftAD: SharedServicesPhase2 1`] = `Array []`;
@@ -1040,8 +1036,6 @@ exports[`there should not be any unsupported resource changes for AWS::EC2::Inst
10401036

10411037
exports[`there should not be any unsupported resource changes for AWS::EC2::Instance: SharedNetworkPhase3 1`] = `Array []`;
10421038

1043-
exports[`there should not be any unsupported resource changes for AWS::EC2::Instance: SharedServicesPhase0 1`] = `Array []`;
1044-
10451039
exports[`there should not be any unsupported resource changes for AWS::EC2::Instance: SharedServicesPhase1 1`] = `Array []`;
10461040

10471041
exports[`there should not be any unsupported resource changes for AWS::EC2::Instance: SharedServicesPhase2 1`] = `Array []`;
@@ -1176,8 +1170,6 @@ exports[`there should not be any unsupported resource changes for AWS::EC2::Tran
11761170

11771171
exports[`there should not be any unsupported resource changes for AWS::EC2::TransitGateway: SharedNetworkPhase3 1`] = `Array []`;
11781172

1179-
exports[`there should not be any unsupported resource changes for AWS::EC2::TransitGateway: SharedServicesPhase0 1`] = `Array []`;
1180-
11811173
exports[`there should not be any unsupported resource changes for AWS::EC2::TransitGateway: SharedServicesPhase1 1`] = `Array []`;
11821174

11831175
exports[`there should not be any unsupported resource changes for AWS::EC2::TransitGateway: SharedServicesPhase2 1`] = `Array []`;
@@ -1307,8 +1299,6 @@ exports[`there should not be any unsupported resource changes for AWS::ElasticLo
13071299

13081300
exports[`there should not be any unsupported resource changes for AWS::ElasticLoadBalancingV2::LoadBalancer: SharedNetworkPhase3 1`] = `Array []`;
13091301

1310-
exports[`there should not be any unsupported resource changes for AWS::ElasticLoadBalancingV2::LoadBalancer: SharedServicesPhase0 1`] = `Array []`;
1311-
13121302
exports[`there should not be any unsupported resource changes for AWS::ElasticLoadBalancingV2::LoadBalancer: SharedServicesPhase1 1`] = `Array []`;
13131303

13141304
exports[`there should not be any unsupported resource changes for AWS::ElasticLoadBalancingV2::LoadBalancer: SharedServicesPhase2 1`] = `Array []`;
@@ -1514,8 +1504,6 @@ exports[`there should not be any unsupported resource changes for AWS::S3::Bucke
15141504

15151505
exports[`there should not be any unsupported resource changes for AWS::S3::Bucket: SharedNetworkPhase3 1`] = `Array []`;
15161506

1517-
exports[`there should not be any unsupported resource changes for AWS::S3::Bucket: SharedServicesPhase0 1`] = `Array []`;
1518-
15191507
exports[`there should not be any unsupported resource changes for AWS::S3::Bucket: SharedServicesPhase1 1`] = `Array []`;
15201508

15211509
exports[`there should not be any unsupported resource changes for AWS::S3::Bucket: SharedServicesPhase2 1`] = `Array []`;
@@ -1691,8 +1679,6 @@ exports[`there should not be any unsupported resource changes for AWS::SecretsMa
16911679

16921680
exports[`there should not be any unsupported resource changes for AWS::SecretsManager::ResourcePolicy: SharedNetworkPhase3 1`] = `Array []`;
16931681

1694-
exports[`there should not be any unsupported resource changes for AWS::SecretsManager::ResourcePolicy: SharedServicesPhase0 1`] = `Array []`;
1695-
16961682
exports[`there should not be any unsupported resource changes for AWS::SecretsManager::ResourcePolicy: SharedServicesPhase1 1`] = `Array []`;
16971683

16981684
exports[`there should not be any unsupported resource changes for AWS::SecretsManager::ResourcePolicy: SharedServicesPhase2 1`] = `Array []`;
@@ -1870,8 +1856,6 @@ exports[`there should not be any unsupported resource changes for AWS::SecretsMa
18701856

18711857
exports[`there should not be any unsupported resource changes for AWS::SecretsManager::Secret: SharedNetworkPhase3 1`] = `Array []`;
18721858

1873-
exports[`there should not be any unsupported resource changes for AWS::SecretsManager::Secret: SharedServicesPhase0 1`] = `Array []`;
1874-
18751859
exports[`there should not be any unsupported resource changes for AWS::SecretsManager::Secret: SharedServicesPhase1 1`] = `Array []`;
18761860

18771861
exports[`there should not be any unsupported resource changes for AWS::SecretsManager::Secret: SharedServicesPhase2 1`] = `Array []`;

0 commit comments

Comments
 (0)