serverless-plugin-additional-stacks
Advanced tools
Comparing version 1.2.0 to 1.3.0
183
index.js
@@ -218,5 +218,5 @@ 'use strict' | ||
promise = promise | ||
.then(() => { | ||
return this.deployStack(stackName, stacks[stackName]) | ||
}) | ||
.then(() => { | ||
return this.deployStack(stackName, stacks[stackName]) | ||
}) | ||
}) | ||
@@ -228,3 +228,3 @@ return promise | ||
deployStack(stackName, stack) { | ||
// Generate the CloudFormation template | ||
// Generate the CloudFomation template | ||
const compiledCloudFormationTemplate = { | ||
@@ -260,12 +260,18 @@ "AWSTemplateFormatVersion": "2010-09-09", | ||
return this.describeStack(fullStackName) | ||
.then(stackStatus => { | ||
if (!stackStatus) { | ||
// Create stack | ||
return this.createStack(stackName, fullStackName, compiledCloudFormationTemplate, stackTags, deployParameters) | ||
} else { | ||
// Update stack | ||
return this.updateStack(stackName, fullStackName, compiledCloudFormationTemplate, stackTags, deployParameters) | ||
} | ||
}) | ||
return this.writeUpdateTemplateToDisk(stackName, compiledCloudFormationTemplate) | ||
.then(() => { return this.describeStack(fullStackName) }) | ||
.then(stackStatus => { | ||
if (this.options.noDeploy) { | ||
this.serverless.cli.log('Did not deploy ' + fullStackName + ' due to --noDeploy') | ||
return Promise.resolve() | ||
} else { | ||
if (!stackStatus) { | ||
// Create stack | ||
return this.createStack(stackName, fullStackName, compiledCloudFormationTemplate, stackTags, deployParameters) | ||
} else { | ||
// Update stack | ||
return this.updateStack(stackName, fullStackName, compiledCloudFormationTemplate, stackTags, deployParameters) | ||
} | ||
} | ||
}) | ||
} | ||
@@ -278,5 +284,5 @@ | ||
promise = promise | ||
.then(() => { | ||
return this.deleteStack(stackName, stacks[stackName]) | ||
}) | ||
.then(() => { | ||
return this.deleteStack(stackName, stacks[stackName]) | ||
}) | ||
}) | ||
@@ -291,5 +297,5 @@ return promise | ||
promise = promise | ||
.then(() => { | ||
return this.infoStack(stackName, stacks[stackName]) | ||
}) | ||
.then(() => { | ||
return this.infoStack(stackName, stacks[stackName]) | ||
}) | ||
}) | ||
@@ -303,19 +309,19 @@ return promise | ||
'describeStacks', { | ||
StackName: fullStackName, | ||
}, | ||
StackName: fullStackName, | ||
}, | ||
this.options.stage, | ||
this.options.region | ||
) | ||
.then(response => { | ||
return response.Stacks && response.Stacks[0] | ||
}) | ||
.then(null, err => { | ||
if (err.message && err.message.match(/does not exist$/)) { | ||
// Stack doesn't exist yet | ||
return null | ||
} else { | ||
// Some other error, let it throw | ||
return Promise.reject(err) | ||
} | ||
}) | ||
.then(response => { | ||
return response.Stacks && response.Stacks[0] | ||
}) | ||
.then(null, err => { | ||
if (err.message && err.message.match(/does not exist$/)) { | ||
// Stack doesn't exist yet | ||
return null | ||
} else { | ||
// Some other error, let it throw | ||
return Promise.reject(err) | ||
} | ||
}) | ||
} | ||
@@ -345,7 +351,18 @@ | ||
) | ||
.then(() => { | ||
return this.waitForStack(stackName, fullStackName, 'create') | ||
}) | ||
.then(() => { | ||
return this.waitForStack(stackName, fullStackName, 'create') | ||
}) | ||
} | ||
writeUpdateTemplateToDisk(stackName, stack) { | ||
this.serverless.cli.log('Writing template for additional stack ' + stackName + '...') | ||
const updateOrCreate = this.createLater ? 'create' : 'update'; | ||
const cfTemplateFilePath = path.join(this.serverless.config.servicePath, | ||
'.serverless', `cloudformation-template-${updateOrCreate}-stack-${stackName}.json`); | ||
this.serverless.utils.writeFileSync(cfTemplateFilePath, stack); | ||
return Promise.resolve(); | ||
} | ||
updateStack(stackName, fullStackName, compiledCloudFormationTemplate, stackTags, deployParameters) { | ||
@@ -371,15 +388,15 @@ // These are the same parameters that Serverless uses in https://github.com/serverless/serverless/blob/master/lib/plugins/aws/lib/updateStack.js | ||
) | ||
.then(() => { | ||
this.serverless.cli.log('Updating additional stack ' + stackName + '...') | ||
return this.waitForStack(stackName, fullStackName, 'update') | ||
}) | ||
.then(null, err => { | ||
if (err.message && err.message.match(/^No updates/)) { | ||
// Stack is unchanged, ignore error | ||
this.serverless.cli.log('Additional stack ' + stackName + ' has not changed.') | ||
return Promise.resolve() | ||
} else { | ||
return Promise.reject(err) | ||
} | ||
}) | ||
.then(() => { | ||
this.serverless.cli.log('Updating additional stack ' + stackName + '...') | ||
return this.waitForStack(stackName, fullStackName, 'update') | ||
}) | ||
.then(null, err => { | ||
if (err.message && err.message.match(/^No updates/)) { | ||
// Stack is unchanged, ignore error | ||
this.serverless.cli.log('Additional stack ' + stackName + ' has not changed.') | ||
return Promise.resolve() | ||
} else { | ||
return Promise.reject(err) | ||
} | ||
}) | ||
} | ||
@@ -395,10 +412,10 @@ | ||
'deleteStack', { | ||
StackName: fullStackName, | ||
}, | ||
StackName: fullStackName, | ||
}, | ||
this.options.stage, | ||
this.options.region | ||
) | ||
.then(() => { | ||
return this.waitForStack(stackName, fullStackName, 'delete') | ||
}) | ||
.then(() => { | ||
return this.waitForStack(stackName, fullStackName, 'delete') | ||
}) | ||
} | ||
@@ -411,9 +428,9 @@ | ||
return this.describeStack(fullStackName) | ||
.then(status => { | ||
if (!status) { | ||
this.serverless.cli.consoleLog(' ' + stackName + ': does not exist') | ||
} else { | ||
this.serverless.cli.consoleLog(' ' + stackName + ': ' + status.StackStatus) | ||
} | ||
}) | ||
.then(status => { | ||
if (!status) { | ||
this.serverless.cli.consoleLog(' ' + stackName + ': does not exist') | ||
} else { | ||
this.serverless.cli.consoleLog(' ' + stackName + ': ' + status.StackStatus) | ||
} | ||
}) | ||
} | ||
@@ -425,24 +442,24 @@ | ||
return this.describeStack(fullStackName) | ||
.then(response => { | ||
if (!response) { | ||
// Stack does not exist | ||
if (dots) this.serverless.cli.consoleLog('') | ||
this.serverless.cli.log('Additional stack ' + stackName + ' removed successfully.') | ||
return | ||
} | ||
const state = this.stackStatusCodes[response.StackStatus] | ||
if (state === 'in_progress') { | ||
// Continue until no longer in progress | ||
this.serverless.cli.printDot() | ||
dots += 1 | ||
return new Promise((resolve, reject) => setTimeout(resolve, 5000)).then(readMore) | ||
} else { | ||
if (dots) this.serverless.cli.consoleLog('') | ||
this.serverless.cli.log('Additional stack ' + stackName + ' ' + this.phrases[operation][state] + ' (' + response.StackStatus + ').') | ||
if (this.stackStatusCodes[response.StackStatus] === 'failure') { | ||
// The operation failed, so return an error to Serverless | ||
return Promise.reject(new Error('Additional stack ' + stackName + ' ' + this.phrases[operation][state] + ' (' + response.StackStatus + ')')) | ||
.then(response => { | ||
if (!response) { | ||
// Stack does not exist | ||
if (dots) this.serverless.cli.consoleLog('') | ||
this.serverless.cli.log('Additional stack ' + stackName + ' removed successfully.') | ||
return | ||
} | ||
} | ||
}) | ||
const state = this.stackStatusCodes[response.StackStatus] | ||
if (state === 'in_progress') { | ||
// Continue until no longer in progress | ||
this.serverless.cli.printDot() | ||
dots += 1 | ||
return new Promise((resolve, reject) => setTimeout(resolve, 5000)).then(readMore) | ||
} else { | ||
if (dots) this.serverless.cli.consoleLog('') | ||
this.serverless.cli.log('Additional stack ' + stackName + ' ' + this.phrases[operation][state] + ' (' + response.StackStatus + ').') | ||
if (this.stackStatusCodes[response.StackStatus] === 'failure') { | ||
// The operation failed, so return an error to Serverless | ||
return Promise.reject(new Error('Additional stack ' + stackName + ' ' + this.phrases[operation][state] + ' (' + response.StackStatus + ')')) | ||
} | ||
} | ||
}) | ||
} | ||
@@ -449,0 +466,0 @@ return readMore() |
{ | ||
"name": "serverless-plugin-additional-stacks", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "repository": {}, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76863
800
2