Skip to content

Commit e7c31ca

Browse files
feat: early config validation (#898)
* feat: add validation to check for email duplicates on account configs * chore: add logs for debugging * feat: make error a concatenation of compareAccelerator and global errors * refactor: embed the duplicate email check in the compare configuration steps like all other validations * chore: remove uneeded email duplicate logic on compare condig step main hanlder * feat: check to ensure the account values under global-options match the respective mandatory key account * fix: check for account key match between global and mandatory account configs * chore: remove uneeded log * refactor: arrow function to simplify if condition * fix: remove accidental import added by ide Co-authored-by: hickeydh-aws <88673813+hickeydh-aws@users.noreply.github.com>
1 parent cd56056 commit e7c31ca

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ aws-landing-zone-configuration.zip
77
**/dist
88
.idea
99
.envrc
10-
.vscode
10+
.vscode

src/core/runtime/src/compare-configurations-step.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export const handler = async (input: StepInput) => {
133133
const { scope, targetAccounts, targetOus } = inputConfig;
134134

135135
const accounts = await loadAccounts(parametersTableName, dynamodb);
136+
136137
const targetAccountKeys: string[] = [];
137138
if (targetAccounts) {
138139
targetAccounts.map(targetAccount => {

src/lib/common-config/src/compare/main.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ export async function compareAcceleratorConfig(props: {
6969
const configChanges = compareConfiguration(previousConfig, modifiedConfig);
7070
if (!configChanges) {
7171
console.log('no differences found');
72+
// Check for duplicate email entry
73+
const acceleratorConfig = AcceleratorConfig.fromObject(modifiedConfig);
74+
checkForEmailDuplicates(acceleratorConfig, errors);
75+
checkForMismatchedAccountKeys(modifiedConfig, errors);
7276
// Validate DDB Pool entries changes
7377
if (!overrideConfig['ov-cidr']) {
74-
const acceleratorConfig = AcceleratorConfig.fromObject(modifiedConfig);
7578
await validate.validateDDBChanges(
7679
acceleratorConfig,
7780
vpcCidrPoolAssignedTable,
@@ -82,6 +85,10 @@ export async function compareAcceleratorConfig(props: {
8285
}
8386
return errors;
8487
}
88+
// Check for duplicate email entry
89+
const acceleratorConfig = AcceleratorConfig.fromObject(modifiedConfig);
90+
checkForEmailDuplicates(acceleratorConfig, errors);
91+
checkForMismatchedAccountKeys(acceleratorConfig, errors);
8592

8693
scopeValidation(scope, configChanges, errors, targetAccounts || [], targetOus || []);
8794

@@ -180,6 +187,33 @@ export async function compareAcceleratorConfig(props: {
180187
return errors;
181188
}
182189

190+
function checkForEmailDuplicates(acceleratorConfig: AcceleratorConfig, errors: string[]) {
191+
const emails = [...acceleratorConfig.getAccountConfigs().map(([_, accountConfig]) => accountConfig.email)];
192+
const duplicateFilteredEmails = [...new Set(emails)];
193+
if (emails.length !== duplicateFilteredEmails.length) {
194+
errors.push(
195+
'Found duplicate entries for account emails under mandatory-account-configs / workload-account-configs',
196+
);
197+
}
198+
}
199+
200+
function checkForMismatchedAccountKeys(acceleratorConfig: AcceleratorConfig, errors: string[]) {
201+
const mandatoryAccountKeys = [
202+
'aws-org-management',
203+
'central-security-services',
204+
'central-operations-services',
205+
'central-log-services',
206+
];
207+
// @ts-ignore
208+
const globalAccountKeys = mandatoryAccountKeys.map(key => acceleratorConfig['global-options'][key].account);
209+
for (const accountKey of globalAccountKeys) {
210+
if (!acceleratorConfig.getMandatoryAccountConfigs().find(accountConfig => accountConfig[0] === accountKey)) {
211+
errors.push(`Global mandatory account ${accountKey} was not found under mandatory-account-configs`);
212+
}
213+
}
214+
return errors;
215+
}
216+
183217
function scopeValidation(
184218
scope: 'FULL' | 'NEW-ACCOUNTS' | 'GLOBAL-OPTIONS' | 'ACCOUNT' | 'OU',
185219
configChanges: Diff[],

0 commit comments

Comments
 (0)