Introduce logical id naming function

This commit is contained in:
Philipp Muens 2019-10-22 11:45:06 +02:00
parent 3cede35cc9
commit 3d2879ef56
4 changed files with 17 additions and 2 deletions

View File

@ -291,6 +291,9 @@ module.exports = {
getApiGatewayLogGroupLogicalId() {
return 'ApiGatewayLogGroup';
},
getApiGatewayAccountCloudWatchRoleResourceLogicalId() {
return 'ApiGatewayAccountCloudWatchRole';
},
// S3
getDeploymentBucketLogicalId() {

View File

@ -456,6 +456,14 @@ describe('#naming()', () => {
});
});
describe('#getApiGatewayAccountCloudWatchRoleResourceLogicalId()', () => {
it('should return the API Gateway account CloudWatch role logical id', () => {
expect(sdk.naming.getApiGatewayAccountCloudWatchRoleResourceLogicalId()).to.equal(
'ApiGatewayAccountCloudWatchRole'
);
});
});
describe('#getDeploymentBucketLogicalId()', () => {
it('should return "ServerlessDeploymentBucket"', () => {
expect(sdk.naming.getDeploymentBucketLogicalId()).to.equal('ServerlessDeploymentBucket');

View File

@ -6,6 +6,7 @@ const { addCustomResourceToService } = require('../../../../customResources');
module.exports = memoize(provider => {
const cfTemplate = provider.serverless.service.provider.compiledCloudFormationTemplate;
const logicalId = provider.naming.getApiGatewayAccountCloudWatchRoleResourceLogicalId();
const customResourceLogicalId = provider.naming.getCustomResourceApiGatewayAccountCloudWatchRoleResourceLogicalId();
const customResourceFunctionLogicalId = provider.naming.getCustomResourceApiGatewayAccountCloudWatchRoleHandlerFunctionLogicalId();
@ -15,7 +16,7 @@ module.exports = memoize(provider => {
const configuredRoleArn = restApi && restApi.role;
if (configuredRoleArn) {
cfTemplate.Resources.apiGatewayCloudWatchRole = {
cfTemplate.Resources[logicalId] = {
Type: 'AWS::ApiGateway::Account',
Properties: {
CloudWatchRoleArn: configuredRoleArn,

View File

@ -14,6 +14,7 @@ describe('ensureApiGatewayCloudWatchRole', () => {
let resources;
let addCustomResourceToServiceStub;
let ensureApiGatewayCloudWatchRole;
const logicalId = 'Id';
const customResourceLogicalId = 'CustomResourceId';
beforeEach(() => {
@ -35,6 +36,7 @@ describe('ensureApiGatewayCloudWatchRole', () => {
},
},
naming: {
getApiGatewayAccountCloudWatchRoleResourceLogicalId: () => logicalId,
getCustomResourceApiGatewayAccountCloudWatchRoleResourceLogicalId: () =>
customResourceLogicalId,
getCustomResourceApiGatewayAccountCloudWatchRoleHandlerFunctionLogicalId: () => 'bar',
@ -53,7 +55,7 @@ describe('ensureApiGatewayCloudWatchRole', () => {
return expect(ensureApiGatewayCloudWatchRole(provider)).to.eventually.be.fulfilled.then(
() => {
expect(_.isObject(resources[customResourceLogicalId])).to.equal(false);
expect(_.isObject(resources.apiGatewayCloudWatchRole)).to.equal(true);
expect(_.isObject(resources[logicalId])).to.equal(true);
}
);
});
@ -74,6 +76,7 @@ describe('ensureApiGatewayCloudWatchRole', () => {
it('Should ensure custom resource on template', () => {
return expect(ensureApiGatewayCloudWatchRole(provider)).to.eventually.be.fulfilled.then(
() => {
expect(_.isObject(resources[logicalId])).to.equal(false);
expect(_.isObject(resources[customResourceLogicalId])).to.equal(true);
}
);