Skip to content

Commit 0c4a412

Browse files
authored
Added function to enable global region (#930)
Co-authored-by: hickeydh <hickeydh@amazon.com>
1 parent 7033e5c commit 0c4a412

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/lib/common/src/util/common.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,31 @@ export class RawConfig {
7575
const configString = await this.getFromFile(configFilePath);
7676
const config = getFormattedObject(configString, format);
7777
const loadConfigResponse = await this.load(config, loadFiles);
78-
// Sending Root Config back
79-
loadConfigResponse.loadFiles.push({
80-
filePath: configFilePath,
81-
fileContent: pretty(configString, format),
82-
});
8378

84-
let updatedRawconfig = replaceDefaults({
79+
let updatedRawConfig = replaceDefaults({
8580
config: getStringFromObject(loadConfigResponse.config, JSON_FORMAT),
8681
acceleratorName: this.props.acceleratorName,
8782
acceleratorPrefix: this.props.acceleratorPrefix,
8883
region: this.props.region,
8984
additionalReplacements: additionalReplacements(loadConfigResponse.config.replacements || {}),
9085
});
9186

92-
updatedRawconfig = await vpcReplacements({
93-
rawConfigStr: updatedRawconfig,
87+
updatedRawConfig = await vpcReplacements({
88+
rawConfigStr: updatedRawConfig,
9489
});
9590

91+
const updatedConfigs = enableGlobalRegion(configString, updatedRawConfig, format);
9692
// Sending Raw Config back
9793
loadConfigResponse.loadFiles.push({
9894
filePath: RAW_CONFIG_FILE,
99-
fileContent: pretty(updatedRawconfig, JSON_FORMAT),
95+
fileContent: pretty(updatedConfigs.rawConfigStr, JSON_FORMAT),
10096
});
10197

98+
// Sending Root Config back
99+
loadConfigResponse.loadFiles.push({
100+
filePath: configFilePath,
101+
fileContent: pretty(updatedConfigs.configStr, format),
102+
});
102103
return {
103104
config: JSON.stringify(loadConfigResponse.config),
104105
loadFiles: loadConfigResponse.loadFiles,
@@ -335,3 +336,19 @@ function randomString(length: number, charSet?: string) {
335336
}
336337
return randomString;
337338
}
339+
340+
function enableGlobalRegion(config: string, rawConfig: string, format: FormatType) {
341+
const rawConfigObj = getFormattedObject(config, format);
342+
const configObj = getFormattedObject(rawConfig, format);
343+
if (!rawConfigObj['global-options']['supported-regions'].includes('us-east-1')) {
344+
console.log('us-east-1 is not inlcuded in supported-regions. Adding.');
345+
configObj['global-options']['supported-regions'].push('us-east-1');
346+
rawConfigObj['global-options']['supported-regions'].push('us-east-1');
347+
} else {
348+
console.log('Global region is added.');
349+
}
350+
351+
const configStr = getStringFromObject(configObj, format);
352+
const rawConfigStr = getStringFromObject(rawConfigObj, format);
353+
return { configStr, rawConfigStr };
354+
}

0 commit comments

Comments
 (0)