diff --git a/src/commands/create-organization-changeset.ts b/src/commands/create-organization-changeset.ts index 6ecc19d6..6b80c456 100644 --- a/src/commands/create-organization-changeset.ts +++ b/src/commands/create-organization-changeset.ts @@ -29,7 +29,7 @@ export class CreateChangeSetCommand extends BaseCliCommand command.option('--output ', 'the serialization format used when printing stacks. Either json or yaml.', 'yaml'); command.option('--output-cross-account-exports ', '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); } @@ -44,8 +45,20 @@ export class PrintStacksCommand extends BaseCliCommand 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); @@ -119,4 +132,5 @@ export interface IPrintStacksCommandArgs extends ICommandArgs { parameters?: string | {}; output?: 'json' | 'yaml'; taskRoleName?: string; + TemplatingContext?: {}; } diff --git a/src/commands/update-stacks.ts b/src/commands/update-stacks.ts index 0cb8c23e..fb579dd1 100644 --- a/src/commands/update-stacks.ts +++ b/src/commands/update-stacks.ts @@ -70,6 +70,7 @@ export class UpdateStacksCommand extends BaseCliCommand', 'maximum number of stacks to be executed concurrently', 1); command.option('--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); } @@ -134,7 +135,20 @@ export class UpdateStacksCommand extends BaseCliCommand { }); -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; diff --git a/test/unit-tests/plugin/impl/sls-build-task-plugin.test.ts b/test/unit-tests/plugin/impl/sls-build-task-plugin.test.ts index 75efeca6..cb43fcc3 100644 --- a/test/unit-tests/plugin/impl/sls-build-task-plugin.test.ts +++ b/test/unit-tests/plugin/impl/sls-build-task-plugin.test.ts @@ -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', () => {