From fd135e033717f2a825544827e11884ba329e0f39 Mon Sep 17 00:00:00 2001 From: Pavel Tcholakov Date: Sun, 12 May 2024 21:09:06 +0200 Subject: [PATCH] Expose a parameters top-level property which maps directly to StackSet parameters --- README.md | 6 +++--- src/stackset.ts | 24 +++++++++++++++++++++--- test/stack-set.test.ts | 10 +++++++--- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index dd83c4c..173a3a2 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,12 @@ const stack = new Stack(); const stackSetStack = new StackSetStack(stack, 'MyStackSet'); new StackSet(stack, 'StackSet', { + parameters: { + SomeParam: 'Value', + }, target: StackSetTarget.fromAccounts({ regions: ['us-east-1'], accounts: ['11111111111'], - parameterOverrides: { - SomeParam: 'overrideValue', - }, }), template: StackSetTemplate.fromStackSetStack(stackSetStack), }); diff --git a/src/stackset.ts b/src/stackset.ts index 7bc9fef..fe0af01 100644 --- a/src/stackset.ts +++ b/src/stackset.ts @@ -139,7 +139,8 @@ interface StackSetTargetConfig { readonly organizationalUnits?: string[]; } -interface TargetBindOptions {} +interface TargetBindOptions { +} /** * Which organizational units and/or accounts the stack set @@ -346,7 +347,8 @@ interface DeploymentTypeConfig { readonly callAs?: CallAs; } -interface DeploymentTypeOptions {} +interface DeploymentTypeOptions { +} export abstract class DeploymentType { /** @@ -475,6 +477,11 @@ export interface StackSetProps { */ readonly operationPreferences?: OperationPreferences; + /** + * The input parameters for the stack set template. + */ + readonly parameters?: StackSetParameter; + /** * Specify a list of capabilities required by your stackset. * @@ -607,6 +614,7 @@ export class StackSet extends Resource implements IStackSet { private readonly _role?: iam.IRole; private readonly permissionModel: PermissionModel; + constructor(scope: Construct, id: string, props: StackSetProps) { super(scope, id, { physicalName: props.stackSetName ?? Lazy.string({ produce: () => Names.uniqueResourceName(this, {}) }), @@ -655,7 +663,17 @@ export class StackSet extends Resource implements IStackSet { permissionModel: deploymentTypeConfig.permissionsModel, callAs: deploymentTypeConfig.callAs, templateUrl: props.template.templateUrl, - stackInstancesGroup: Lazy.any({ produce: () => { return this.stackInstances; } }), + stackInstancesGroup: Lazy.any({ + produce: () => { + return this.stackInstances; + }, + }), + parameters: props.parameters ? Object.entries(props.parameters).map((entry) => { + return { + parameterKey: entry[0], + parameterValue: entry[1], + }; + }) : undefined, }); // the file asset bucket deployment needs to complete before the stackset can deploy diff --git a/test/stack-set.test.ts b/test/stack-set.test.ts index 4cc0657..1dd771f 100644 --- a/test/stack-set.test.ts +++ b/test/stack-set.test.ts @@ -35,11 +35,11 @@ test('default', () => { target: StackSetTarget.fromAccounts({ regions: ['us-east-1'], accounts: ['11111111111'], - parameterOverrides: { - Param1: 'Value1', - }, }), template: StackSetTemplate.fromStackSetStack(new StackSetStack(stack, 'Stack')), + parameters: { + Param1: 'Value1', + }, }); Template.fromStack(stack).hasResourceProperties('AWS::CloudFormation::StackSet', { @@ -48,6 +48,10 @@ test('default', () => { TemplateURL: { 'Fn::Sub': 'https://s3.${AWS::Region}.${AWS::URLSuffix}/cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a.json', }, + Parameters: [{ + ParameterKey: 'Param1', + ParameterValue: 'Value1', + }], StackInstancesGroup: [{ Regions: ['us-east-1'], DeploymentTargets: {