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
3 changes: 2 additions & 1 deletion src/commands/create-organization-changeset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CreateChangeSetCommand extends BaseCliCommand<ICreateChangeSetComma
return;
}

const template = await TemplateRoot.create(command.templateFile);
const template = await TemplateRoot.create(command.templateFile, { TemplatingContext: command.TemplatingContext });
const state = await this.getState(command);

GlobalState.Init(state, template);
Expand Down Expand Up @@ -60,6 +60,7 @@ export class CreateChangeSetCommand extends BaseCliCommand<ICreateChangeSetComma
export interface ICreateChangeSetCommandArgs extends ICommandArgs {
masterAccountId?: any;
templateFile: string;
TemplatingContext?: {};
changeSetName?: string;
output?: 'json' | 'yaml';
}
18 changes: 16 additions & 2 deletions src/commands/print-stacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class PrintStacksCommand extends BaseCliCommand<IPrintStacksCommandArgs>
command.option('--output <output>', 'the serialization format used when printing stacks. Either json or yaml.', 'yaml');
command.option('--output-cross-account-exports <output-path>', 'when set, output well generate cross account exports as part of cfn parameter', false);
command.option('--no-print-parameters', 'will not print parameter files when printing stacks');
command.option('--templating-context [templating-context]', 'JSON string representing the templating context', undefined);
super.addOptions(command);
}

Expand All @@ -44,8 +45,20 @@ export class PrintStacksCommand extends BaseCliCommand<IPrintStacksCommandArgs>
if (ValidateOrganizationCommand.SkipValidationForTasks) {
return;
}

const template = await UpdateStacksCommand.createTemplateUsingOverrides(command as IUpdateStacksCommandArgs, command.templateFile);
let templatingContext;
if (command.TemplatingContext && typeof command.TemplatingContext === 'string') {
try {
templatingContext = JSON.parse(command.TemplatingContext);
} catch (e) {
throw new OrgFormationError('Invalid templating context JSON provided');
}
} else {
templatingContext = command.TemplatingContext;
}
const template = await UpdateStacksCommand.createTemplateUsingOverrides(
{ ...command, TemplatingContext: templatingContext } as IUpdateStacksCommandArgs,
command.templateFile
);
const state = await this.getState(command);
GlobalState.Init(state, template);
const parameters = this.parseCfnParameters(command.parameters);
Expand Down Expand Up @@ -119,4 +132,5 @@ export interface IPrintStacksCommandArgs extends ICommandArgs {
parameters?: string | {};
output?: 'json' | 'yaml';
taskRoleName?: string;
TemplatingContext?: {};
}
17 changes: 16 additions & 1 deletion src/commands/update-stacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
command.option('--max-concurrent-stacks <max-concurrent-stacks>', 'maximum number of stacks to be executed concurrently', 1);
command.option('--failed-stacks-tolerance <failed-stacks-tolerance>', 'the number of failed stacks after which execution stops', 0);
command.option('--large-template-bucket-name [large-template-bucket-name]', 'bucket used when uploading large templates. default is to create a bucket just-in-time in the target account');
command.option('--templating-context [templating-context]', 'JSON string representing the templating context', undefined);
super.addOptions(command);
}

Expand All @@ -94,7 +95,7 @@
const partition = command.isPartition === true;
const taskViaRoleArn = command.taskViaRoleArn;
const stackName = command.stackName;
const templateFile = command.templateFile;

Check warning on line 98 in src/commands/update-stacks.ts

View workflow job for this annotation

GitHub Actions / test

'templateFile' is assigned a value but never used
let stackPolicy = command.stackPolicy;
const tags = command.tags;
if (updateProtection !== undefined) {
Expand Down Expand Up @@ -134,7 +135,20 @@
},
};
}
const template = await UpdateStacksCommand.createTemplateUsingOverrides(command, templateFile);
let templatingContext;
if (command.TemplatingContext && typeof command.TemplatingContext === 'string') {
try {
templatingContext = JSON.parse(command.TemplatingContext);
} catch (e) {
throw new OrgFormationError('Invalid templating context JSON provided');
}
} else {
templatingContext = command.TemplatingContext;
}
const template = await UpdateStacksCommand.createTemplateUsingOverrides(
{ ...command, TemplatingContext: templatingContext } as IUpdateStacksCommandArgs,
command.templateFile
);
const parameters = this.parseCfnParameters(command.parameters);
const state = await this.getState(command);
GlobalState.Init(state, template);
Expand Down Expand Up @@ -180,4 +194,5 @@
disableStackRollbacks?: boolean;
stackPolicy?: {};
tags?: {};
TemplatingContext?: {};
}
38 changes: 20 additions & 18 deletions test/unit-tests/plugin/impl/cdk-build-task-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,26 @@ describe('when creating cdk plugin', () => {

});

describe('when validating task', () => {
let plugin: CdkBuildTaskPlugin;
let commandArgs: ICdkCommandArgs;

beforeEach(() => {
plugin = new CdkBuildTaskPlugin();
commandArgs = plugin.convertToCommandArgs( {
FilePath: './tasks.yaml',
Type: 'cdk',
MaxConcurrentTasks: 1,
FailedTaskTolerance: 4,
LogicalName: 'test-task',
Path: './',
TaskRoleName: 'TaskRole',
OrganizationBinding: { IncludeMasterAccount: true}},
{ organizationFile: './organization.yml'} as any);
});
});
// This doesn't do anything so let's remove it for now - throws errors
// TODO: If you like CDK, you should add some tests here :D
// describe('when validating task', () => {
// let plugin: CdkBuildTaskPlugin;
// let commandArgs: ICdkCommandArgs;

// beforeEach(() => {
// plugin = new CdkBuildTaskPlugin();
// commandArgs = plugin.convertToCommandArgs( {
// FilePath: './tasks.yaml',
// Type: 'cdk',
// MaxConcurrentTasks: 1,
// FailedTaskTolerance: 4,
// LogicalName: 'test-task',
// Path: './',
// TaskRoleName: 'TaskRole',
// OrganizationBinding: { IncludeMasterAccount: true}},
// { organizationFile: './organization.yml'} as any);
// });
// });

describe('when resolving attribute expressions on update', () => {
let spawnProcessForAccountSpy: jest.SpyInstance;
Expand Down
41 changes: 21 additions & 20 deletions test/unit-tests/plugin/impl/sls-build-task-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,27 @@ describe('when creating sls plugin', () => {
});
});


describe('when validating task', () => {
let plugin: SlsBuildTaskPlugin;
let commandArgs: ISlsCommandArgs;

beforeEach(() => {
plugin = new SlsBuildTaskPlugin();
commandArgs = plugin.convertToCommandArgs( {
FilePath: './tasks.yaml',
Type: 'update-serverless.com',
MaxConcurrentTasks: 1,
FailedTaskTolerance: 4,
LogicalName: 'test-task',
Path: './',
Config: './README.md',
TaskRoleName: 'TaskRole',
OrganizationBinding: { IncludeMasterAccount: true}},
{ organizationFile: './organization.yml'} as any);
});
});
// There are no tests here so this just errors out
// TODO: If you like Serverless, you should add tests here :D
// describe('when validating task', () => {
// let plugin: SlsBuildTaskPlugin;
// let commandArgs: ISlsCommandArgs;

// beforeEach(() => {
// plugin = new SlsBuildTaskPlugin();
// commandArgs = plugin.convertToCommandArgs( {
// FilePath: './tasks.yaml',
// Type: 'update-serverless.com',
// MaxConcurrentTasks: 1,
// FailedTaskTolerance: 4,
// LogicalName: 'test-task',
// Path: './',
// Config: './README.md',
// TaskRoleName: 'TaskRole',
// OrganizationBinding: { IncludeMasterAccount: true}},
// { organizationFile: './organization.yml'} as any);
// });
// });


describe('when resolving attribute expressions on update', () => {
Expand Down
Loading