Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ServerlessAWSPseudoParameters {

addParameters() {

const resources = this.serverless.service.provider.compiledCloudFormationTemplate.Resources;
const template = this.serverless.service.provider.compiledCloudFormationTemplate;
const skipRegionReplace = this.skipRegionReplace;
const consoleLog = this.serverless.cli.consoleLog;

Expand All @@ -22,14 +22,13 @@ class ServerlessAWSPseudoParameters {
consoleLog('Skipping automatic replacement of regions with account region!');
}

// loop through all resources, and check all (string) properties for any #{AWS::}
// loop through the entire template, and check all (string) properties for any #{AWS::}
// reference. If found, replace the value with an Fn::Sub reference
Object.keys(resources).forEach(identifier => {
if ("Properties" in resources[identifier]) {
replaceChildNodes(resources[identifier].Properties, identifier)
}
Object.keys(template).forEach(identifier => {
replaceChildNodes(template[identifier], identifier)
});


function isDict(v) {
return typeof v === 'object' && v !== null && !(v instanceof Array) && !(v instanceof Date);
}
Expand Down
66 changes: 66 additions & 0 deletions lib/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,71 @@ describe('Plugin', () => {

});

describe('using pseudo parameters in the outputs', () => {
let serverlessPseudoParamsPlugin;
let resultTemplate;

beforeEach(() => {
const serverless = {
cli: {
log: () => {},
consoleLog: () => {}
},
service: {
provider: {
compiledCloudFormationTemplate: {},
}
},
};
serverless.service.provider.compiledCloudFormationTemplate = { Outputs: {
acmeOutput: {
AccountId: "#{AWS::AccountId}",
Region: "#{AWS::Region}",
NotificationARNs: "#{AWS::NotificationARNs}",
NoValue: "#{AWS::NoValue}",
Partition: "#{AWS::Partition}",
StackId: "#{AWS::StackId}",
StackName: "#{AWS::StackName}",
URLSuffix: "#{AWS::URLSuffix}",
}
} };
serverlessPseudoParamsPlugin = new Plugin(serverless);
serverlessPseudoParamsPlugin.serverless.service.service = 'foo-service';
serverlessPseudoParamsPlugin.addParameters();
resultTemplate = serverlessPseudoParamsPlugin.serverless.service.provider.compiledCloudFormationTemplate;
expect(Object.keys(resultTemplate.Outputs.acmeOutput).length).toEqual(8);
});

it('replaces #{AWS::[VAR]} with the correct CF pseudo parameter', () => {
expect(Object.keys(resultTemplate.Outputs.acmeOutput).length).toEqual(8);
});

it('replaces #{AWS::AccountId} with the ${AWS::AccountId} pseudo parameter', () => {
expect(resultTemplate.Outputs.acmeOutput.AccountId).toEqual({ 'Fn::Sub': '${AWS::AccountId}' });
});
it('replaces #{AWS::Region} with the ${AWS::Region} pseudo parameter', () => {
expect(resultTemplate.Outputs.acmeOutput.Region).toEqual({ 'Fn::Sub': '${AWS::Region}' });
});
it('replaces #{AWS::NotificationARNs} with the ${AWS::NotificationARNs} pseudo parameter', () => {
expect(resultTemplate.Outputs.acmeOutput.NotificationARNs).toEqual({ 'Fn::Sub': '${AWS::NotificationARNs}' });
});
it('replaces #{AWS::NoValue} with the ${AWS::NoValue} pseudo parameter', () => {
expect(resultTemplate.Outputs.acmeOutput.NoValue).toEqual({ 'Fn::Sub': '${AWS::NoValue}' });
});
it('replaces #{AWS::Partition} with the ${AWS::Partition} pseudo parameter', () => {
expect(resultTemplate.Outputs.acmeOutput.Partition).toEqual({ 'Fn::Sub': '${AWS::Partition}' });
});
it('replaces #{AWS::StackId} with the ${AWS::StackId} pseudo parameter', () => {
expect(resultTemplate.Outputs.acmeOutput.StackId).toEqual({ 'Fn::Sub': '${AWS::StackId}' });
});
it('replaces #{AWS::StackName} with the ${AWS::StackName} pseudo parameter', () => {
expect(resultTemplate.Outputs.acmeOutput.StackName).toEqual({ 'Fn::Sub': '${AWS::StackName}' });
});
it('replaces #{AWS::URLSuffix} with the ${AWS::URLSuffix} pseudo parameter', () => {
expect(resultTemplate.Outputs.acmeOutput.URLSuffix).toEqual({ 'Fn::Sub': '${AWS::URLSuffix}' });
});
})



});
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.