Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional Capability when Transform is detected #5997

Merged
merged 2 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/plugins/aws/deploy/lib/createStack.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ module.exports = {
Tags: Object.keys(stackTags).map((key) => ({ Key: key, Value: stackTags[key] })), Tags: Object.keys(stackTags).map((key) => ({ Key: key, Value: stackTags[key] })),
}; };


if (this.serverless.service.provider.compiledCloudFormationTemplate &&
this.serverless.service.provider.compiledCloudFormationTemplate.Transform) {
params.Capabilities.push('CAPABILITY_AUTO_EXPAND');
}

if (this.serverless.service.provider.cfnRole) { if (this.serverless.service.provider.cfnRole) {
params.RoleARN = this.serverless.service.provider.cfnRole; params.RoleARN = this.serverless.service.provider.cfnRole;
} }
Expand Down
14 changes: 14 additions & 0 deletions lib/plugins/aws/deploy/lib/createStack.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ describe('createStack', () => {
}); });
}); });


it('should add CAPABILITY_AUTO_EXPAND if a Transform directive is specified', () => {
awsDeploy.serverless.service.provider
.compiledCloudFormationTemplate = { Transform: 'MyMacro' };

const createStackStub = sandbox
.stub(awsDeploy.provider, 'request').resolves();
sandbox.stub(awsDeploy, 'monitorStack').resolves();

return awsDeploy.create().then(() => {
expect(createStackStub.args[0][2].Capabilities)
.to.contain('CAPABILITY_AUTO_EXPAND');
});
});

it('should use CloudFormation service role ARN if it is specified', () => { it('should use CloudFormation service role ARN if it is specified', () => {
awsDeploy.serverless.service.provider.cfnRole = 'arn:aws:iam::123456789012:role/myrole'; awsDeploy.serverless.service.provider.cfnRole = 'arn:aws:iam::123456789012:role/myrole';


Expand Down
10 changes: 10 additions & 0 deletions lib/plugins/aws/lib/updateStack.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ module.exports = {
Tags: Object.keys(stackTags).map((key) => ({ Key: key, Value: stackTags[key] })), Tags: Object.keys(stackTags).map((key) => ({ Key: key, Value: stackTags[key] })),
}; };


if (this.serverless.service.provider.compiledCloudFormationTemplate &&
this.serverless.service.provider.compiledCloudFormationTemplate.Transform) {
params.Capabilities.push('CAPABILITY_AUTO_EXPAND');
}

if (this.serverless.service.provider.cfnRole) { if (this.serverless.service.provider.cfnRole) {
params.RoleARN = this.serverless.service.provider.cfnRole; params.RoleARN = this.serverless.service.provider.cfnRole;
} }
Expand Down Expand Up @@ -73,6 +78,11 @@ module.exports = {
Tags: Object.keys(stackTags).map((key) => ({ Key: key, Value: stackTags[key] })), Tags: Object.keys(stackTags).map((key) => ({ Key: key, Value: stackTags[key] })),
}; };


if (this.serverless.service.provider.compiledCloudFormationTemplate &&
this.serverless.service.provider.compiledCloudFormationTemplate.Transform) {
params.Capabilities.push('CAPABILITY_AUTO_EXPAND');
}

if (this.serverless.service.provider.cfnRole) { if (this.serverless.service.provider.cfnRole) {
params.RoleARN = this.serverless.service.provider.cfnRole; params.RoleARN = this.serverless.service.provider.cfnRole;
} }
Expand Down
25 changes: 25 additions & 0 deletions lib/plugins/aws/lib/updateStack.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ describe('updateStack', () => {
}); });
}); });


it('should add CAPABILITY_AUTO_EXPAND if a Transform directive is specified', () => {
awsDeploy.serverless.service.provider
.compiledCloudFormationTemplate = { Transform: 'MyMacro' };

const createStackStub = sinon.stub(awsDeploy.provider, 'request').resolves();
sinon.stub(awsDeploy, 'monitorStack').resolves();

return awsDeploy.createFallback().then(() => {
expect(createStackStub.args[0][2].Capabilities)
.to.contain('CAPABILITY_AUTO_EXPAND');
awsDeploy.provider.request.restore();
awsDeploy.monitorStack.restore();
});
});

it('should use CloudFormation service role if it is specified', () => { it('should use CloudFormation service role if it is specified', () => {
awsDeploy.serverless.service.provider.cfnRole = 'arn:aws:iam::123456789012:role/myrole'; awsDeploy.serverless.service.provider.cfnRole = 'arn:aws:iam::123456789012:role/myrole';


Expand Down Expand Up @@ -175,6 +190,16 @@ describe('updateStack', () => {
return awsDeploy.update(); return awsDeploy.update();
}); });


it('should add CAPABILITY_AUTO_EXPAND if a Transform directive is specified', () => {
awsDeploy.serverless.service.provider
.compiledCloudFormationTemplate = { Transform: 'MyMacro' };

return awsDeploy.update().then(() => {
expect(updateStackStub.args[0][2].Capabilities)
.to.contain('CAPABILITY_AUTO_EXPAND');
});
});

it('should use CloudFormation service role if it is specified', () => { it('should use CloudFormation service role if it is specified', () => {
awsDeploy.serverless.service.provider.cfnRole = 'arn:aws:iam::123456789012:role/myrole'; awsDeploy.serverless.service.provider.cfnRole = 'arn:aws:iam::123456789012:role/myrole';


Expand Down