Skip to content

Commit e0b68a4

Browse files
committed
saniize change set name.
1 parent 77dfa01 commit e0b68a4

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

lib/CloudFormationDeployer.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ function tryParseJson(stringContent) {
1313
}
1414
}
1515

16+
function getChangeSetName(changeSetName) {
17+
let newChangeSetName = '';
18+
if (!changeSetName[0].match(/[a-z]/ig)) {
19+
newChangeSetName = 'v';
20+
}
21+
22+
newChangeSetName += changeSetName.replace(/[^a-z0-9-]/gi, '-');
23+
24+
return newChangeSetName;
25+
}
26+
1627
class CloudFormationDeployer {
1728
constructor(region, bucketManager, deploymentBucket) {
1829
this.cloudFormationClient = new CloudFormation({ region });
@@ -159,7 +170,9 @@ class CloudFormationDeployer {
159170
await iteratePromise();
160171
}
161172

162-
async waitForChangeSetCreation(stackName, changeSetName) {
173+
async waitForChangeSetCreation(stackName, rawChangeSetName) {
174+
const changeSetName = getChangeSetName(rawChangeSetName);
175+
163176
let timeout = new Date();
164177
let timeoutLength = 60 * 1000;
165178
timeout.setTime(timeout.getTime() + timeoutLength);
@@ -213,9 +226,11 @@ class CloudFormationDeployer {
213226
let region = this.cloudFormationClient.config.region;
214227
console.log(`Starting Configuration of Stack: ${options.stackName} in ${region}`);
215228

229+
const changeSetName = getChangeSetName(options.changeSetName);
230+
216231
let stackExists = await this.stackExists(options.stackName);
217232
let stackParameters = {
218-
ChangeSetName: options.changeSetName.replace(/[^a-z0-9]/gi, '-'),
233+
ChangeSetName: changeSetName,
219234
StackName: options.stackName,
220235
Capabilities: ['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM'],
221236
ChangeSetType: stackExists ? 'UPDATE' : 'CREATE',
@@ -258,7 +273,7 @@ class CloudFormationDeployer {
258273
}
259274

260275
let executeParameters = {
261-
ChangeSetName: stackParameters.ChangeSetName,
276+
ChangeSetName: getChangeSetName(stackParameters.ChangeSetName),
262277
StackName: options.stackName
263278
};
264279

@@ -393,7 +408,7 @@ class CloudFormationDeployer {
393408
}
394409
}
395410

396-
const changeSetName = options.changeSetName.replace(/[^a-z0-9]/gi, '-');
411+
const changeSetName = getChangeSetName(options.changeSetName);
397412
if (stackExists) {
398413
console.log('Updating stack set...');
399414
stackParameters.OperationId = `${changeSetName}-update`;
@@ -506,8 +521,7 @@ class CloudFormationDeployer {
506521
}
507522
}
508523

509-
const changeSetName = options.changeSetName.replace(/[^a-z0-9]/gi, '-');
510-
524+
const changeSetName = getChangeSetName(options.changeSetName);
511525
if (stackExists) {
512526
console.log('Updating organizational stack set, stack will be updated asynchronously');
513527
stackParameters.OperationId = `${changeSetName}-update`;

0 commit comments

Comments
 (0)