-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstackset.ts
710 lines (640 loc) · 23.3 KB
/
stackset.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
import {
aws_cloudformation as cfn,
aws_iam as iam,
IResource,
Lazy,
Names,
Resource,
} from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { StackSetStack, fileAssetResourceNames } from './stackset-stack';
/**
* Represents a StackSet CloudFormation template
*/
export abstract class StackSetTemplate {
/**
* @param stack the stack to use as the base for the stackset template
* @returns StackSetTemplate
*/
public static fromStackSetStack(stack: StackSetStack): StackSetTemplate {
return { templateUrl: stack._getTemplateUrl() };
}
/**
* The S3 URL of the StackSet template
*/
public abstract readonly templateUrl: string;
}
/**
* The type of StackSet account filter
*/
enum AccountFilterType {
/**
* _Only_ deploys to specified accounts
*/
INTERSECTION = 'INTERSECTION',
/**
* _Does not_ deploy to the specified accounts
*/
DIFFERENCE = 'DIFFERENCE',
/**
* (default value) include both OUs and Accounts
* Allows you to deploy to an OU _and_ specific accounts in a different OU
*/
UNION = 'UNION',
/**
* Only deploy to accounts in an OU
*/
NONE = 'NONE',
}
/**
* CloudFormation stack parameters
*/
export type StackSetParameter = { [key: string]: string };
/**
* Common options for deploying a StackSet to a target
*/
export interface TargetOptions {
/**
* A list of regions the Stack should be deployed to.
*
* If {@link StackSetProps.operationPreferences.regionOrder} is specified
* then the StackSet will be deployed sequentially otherwise it will be
* deployed to all regions in parallel.
*/
readonly regions: string[];
/**
* Parameter overrides that should be applied to only this target
*
* @default - use parameter overrides specified in {@link StackSetProps.parameterOverrides}
*/
readonly parameterOverrides?: StackSetParameter;
}
/**
* Options for deploying a StackSet to a set of Organizational Units (OUs)
*/
export interface OrganizationsTargetOptions extends TargetOptions {
/**
* A list of organizational unit ids to deploy to. The StackSet will
* deploy the provided Stack template to all accounts in the OU.
* This can be further filtered by specifying either `additionalAccounts`
* or `excludeAccounts`.
*
* If the `deploymentType` is specified with `autoDeployEnabled` then
* the StackSet will automatically deploy the Stack to new accounts as they
* are added to the specified `organizationalUnits`
*/
readonly organizationalUnits: string[];
/**
* A list of additional AWS accounts to deploy the StackSet to. This can be
* used to deploy the StackSet to additional AWS accounts that exist in a
* different OU than what has been provided in `organizationalUnits`
*
* @default - Stacks will only be deployed to accounts that exist in the
* specified organizationalUnits
*/
readonly additionalAccounts?: string[];
/**
* A list of AWS accounts to exclude from deploying the StackSet to. This can
* be useful if there are accounts that exist in an OU that is provided in
* `organizationalUnits`, but you do not want the StackSet to be deployed.
*
* @default - Stacks will be deployed to all accounts that exist in the OUs
* specified in the organizationUnits property
*/
readonly excludeAccounts?: string[];
}
/**
* Options for deploying a StackSet to a list of AWS accounts
*/
export interface AccountsTargetOptions extends TargetOptions {
/**
* A list of AWS accounts to deploy the StackSet to
*/
readonly accounts: string[];
}
interface Parameter {
readonly parameterKey: string;
readonly parameterValue: string;
}
interface StackSetTargetConfig {
readonly accountFilterType: AccountFilterType;
readonly regions: string[];
readonly parameterOverrides?: Parameter[];
readonly accounts?: string[];
readonly organizationalUnits?: string[];
}
interface TargetBindOptions {}
/**
* Which organizational units and/or accounts the stack set
* should be deployed to.
*
* `fromAccounts` can be used to deploy the stack set to specific AWS accounts
*
* `fromOrganizationalUnits` can be used to deploy the stack set to specific organizational units
* and optionally include additional accounts from other OUs, or exclude accounts from the specified
* OUs
*
* @example
* // deploy to specific accounts
* StackSetTarget.fromAccounts({
* accounts: ['11111111111', '22222222222'],
* regions: ['us-east-1', 'us-east-2'],
* });
*
* // deploy to OUs and 1 additional account
* StackSetTarget.fromOrganizationalUnits({
* regions: ['us-east-1', 'us-east-2'],
* organizationalUnits: ['ou-1111111', 'ou-2222222'],
* additionalAccounts: ['33333333333'],
* });
*
* // deploy to OUs but exclude 1 account
* StackSetTarget.fromOrganizationalUnits({
* regions: ['us-east-1', 'us-east-2'],
* organizationalUnits: ['ou-1111111', 'ou-2222222'],
* excludeAccounts: ['11111111111'],
* });
*/
export abstract class StackSetTarget {
/**
* Deploy the StackSet to a list of accounts
*
* @example
* StackSetTarget.fromAccounts({
* accounts: ['11111111111', '22222222222'],
* regions: ['us-east-1', 'us-east-2'],
* });
*/
public static fromAccounts(options: AccountsTargetOptions): StackSetTarget {
return new AccountsTarget(options);
};
/**
* Deploy the StackSet to a list of AWS Organizations organizational units.
*
* You can optionally include/exclude individual AWS accounts.
*
* @example
* StackSetTarget.fromOrganizationalUnits({
* regions: ['us-east-1', 'us-east-2'],
* organizationalUnits: ['ou-1111111', 'ou-2222222'],
* });
*/
public static fromOrganizationalUnits(options: OrganizationsTargetOptions): StackSetTarget {
return new OrganizationsTarget(options);
}
/**
* @internal
*/
protected _renderParameters(parameters?: StackSetParameter): Parameter[] | undefined {
if (!parameters) return undefined;
const overrides: Parameter[] = [];
for (const [key, value] of Object.entries(parameters ?? {})) {
overrides.push({
parameterKey: key,
parameterValue: value,
});
}
return overrides;
}
/**
* Render the configuration for a StackSet target
*
* @internal
*/
public abstract _bind(scope: Construct, options?: TargetBindOptions): StackSetTargetConfig;
}
class AccountsTarget extends StackSetTarget {
constructor(private readonly options: AccountsTargetOptions) {
super();
}
public _bind(_scope: Construct, _options: TargetBindOptions = {}): StackSetTargetConfig {
return {
regions: this.options.regions,
parameterOverrides: this._renderParameters(this.options.parameterOverrides),
accountFilterType: AccountFilterType.INTERSECTION,
accounts: this.options.accounts,
};
}
}
class OrganizationsTarget extends StackSetTarget {
constructor(private readonly options: OrganizationsTargetOptions) {
super();
}
public _bind(_scope: Construct, _options: TargetBindOptions = {}): StackSetTargetConfig {
if (this.options.excludeAccounts && this.options.additionalAccounts) {
throw new Error("cannot specify both 'excludeAccounts' and 'additionalAccounts'");
}
const filterType = this.options.additionalAccounts ? AccountFilterType.UNION
: this.options.excludeAccounts ? AccountFilterType.DIFFERENCE
: AccountFilterType.NONE;
return {
regions: this.options.regions,
parameterOverrides: this._renderParameters(this.options.parameterOverrides),
accountFilterType: filterType,
organizationalUnits: this.options.organizationalUnits,
accounts: this.options.additionalAccounts ?? this.options.excludeAccounts,
};
}
}
/**
* Options for StackSets that are managed by AWS Organizations.
*/
export interface ServiceManagedOptions {
/**
* Whether or not the StackSet should automatically create/remove the Stack
* from AWS accounts that are added/removed from an organizational unit.
*
* This has no effect if {@link StackSetTarget.fromAccounts} is used
*
* @default true
*/
readonly autoDeployEnabled?: boolean;
/**
* Whether stacks should be removed from AWS accounts that are removed
* from an organizational unit.
*
* By default the stack will be retained (not deleted)
*
* This has no effect if {@link StackSetTarget.fromAccounts} is used
*
* @default true
*/
readonly autoDeployRetainStacks?: boolean;
/**
* Whether or not the account this StackSet is deployed from is the delegated admin account.
*
* Set this to `false` if you are using the AWS Organizations management account instead.
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-orgs-delegated-admin.html
*
* @default true
*/
readonly delegatedAdmin?: boolean;
}
/**
* Options for StackSets that are not managed by AWS Organizations.
*/
export interface SelfManagedOptions {
/**
* The name of the stackset execution role that already exists in each target AWS account.
* This role must be configured with a trust policy that allows `sts:AssumeRole` from the `adminRole`.
*
* In addition this role must have the necessary permissions to manage the resources created by the stackset.
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-prereqs-self-managed.html#stacksets-prereqs-accountsetup
*
* @default - AWSCloudFormationStackSetExecutionRole
*/
readonly executionRoleName?: string;
/**
* The admin role that CloudFormation will use to perform stackset operations.
* This role should only have permissions to be assumed by the CloudFormation service
* and to assume the execution role in each individual account.
*
* When you create the execution role it must have an assume role policy statement which
* allows `sts:AssumeRole` from this admin role.
*
* To grant specific users/groups access to use this role to deploy stacksets they must have
* a policy that allows `iam:GetRole` & `iam:PassRole` on this role resource.
*
* @default - a default role will be created
*/
readonly adminRole?: iam.IRole;
}
enum PermissionModel {
SERVICE_MANAGED = 'SERVICE_MANAGED',
SELF_MANAGED = 'SELF_MANAGED',
}
interface DeploymentTypeConfig {
readonly permissionsModel: PermissionModel;
readonly executionRoleName?: string;
readonly adminRole?: iam.IRole;
readonly autoDeployEnabled?: boolean;
readonly autoDeployRetainStacks?: boolean;
readonly callAs?: CallAs;
}
interface DeploymentTypeOptions {}
export abstract class DeploymentType {
/**
* StackSets deployed using service managed permissions allow you to deploy
* StackSet instances to accounts within an AWS Organization. Using this module
* AWS Organizations will handle creating the necessary IAM roles and setting up the
* required permissions.
*
* This model also allows you to enable automated deployments which allows the StackSet
* to be automatically deployed to new accounts that are added to your organization in the future.
*
* This model requires you to be operating in either the AWS Organizations management account
* or the delegated administrator account
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-concepts.html#stacksets-concepts-stackset-permission-models
*/
public static serviceManaged(options: ServiceManagedOptions = {}): DeploymentType {
return new ManagedDeploymentType(options);
}
/**
* StackSets deployed using the self managed model require you to create the necessary
* IAM roles in the source and target AWS accounts and to setup the required IAM permissions.
*
* Using this model you can only deploy to AWS accounts that have the necessary IAM roles/permissions
* pre-created.
*/
public static selfManaged(options: SelfManagedOptions = {}): DeploymentType {
return new SelfDeploymentType(options);
}
/**
* Render the deployment type config
*
* @internal
*/
public abstract _bind(scope: Construct, options?: DeploymentTypeOptions): DeploymentTypeConfig;
}
class ManagedDeploymentType extends DeploymentType {
constructor(private readonly options?: ServiceManagedOptions) {
super();
}
public _bind(_scope: Construct, _options: DeploymentTypeOptions = {}): DeploymentTypeConfig {
const autoDeployEnabled = this.options?.autoDeployEnabled ?? true;
if (!autoDeployEnabled && this.options?.autoDeployRetainStacks !== undefined) {
throw new Error('autoDeployRetainStacks only applies if autoDeploy is enabled');
}
return {
permissionsModel: PermissionModel.SERVICE_MANAGED,
autoDeployEnabled,
callAs: (this.options?.delegatedAdmin ?? true) ? CallAs.DELEGATED_ADMIN : CallAs.SELF,
autoDeployRetainStacks: autoDeployEnabled ? (this.options?.autoDeployRetainStacks ?? true)
: undefined,
};
}
}
class SelfDeploymentType extends DeploymentType {
constructor(private readonly options?: SelfManagedOptions) {
super();
}
public _bind(_scope: Construct, _options: DeploymentTypeOptions = {}): DeploymentTypeConfig {
return {
permissionsModel: PermissionModel.SELF_MANAGED,
adminRole: this.options?.adminRole,
executionRoleName: this.options?.executionRoleName,
};
}
}
export interface StackSetProps {
/**
* Which accounts/OUs and regions to deploy the StackSet to
*/
readonly target: StackSetTarget;
/**
* The Stack that will be deployed to the target
*/
readonly template: StackSetTemplate;
/**
* The name of the stack set
*
* @default - CloudFormation generated name
*/
readonly stackSetName?: string;
/**
* An optional description to add to the StackSet
*
* @default - no description
*/
readonly description?: string;
/**
* The type of deployment for this StackSet. The deployment can either be managed by
* AWS Organizations (i.e. DeploymentType.serviceManaged()) or by the AWS account that
* the StackSet is deployed from.
*
* In order to use DeploymentType.serviceManaged() the account needs to either be the
* organizations's management account or a delegated administrator account.
*
* @default DeploymentType.selfManaged()
*/
readonly deploymentType?: DeploymentType;
/**
* If this is `true` then StackSets will perform non-conflicting operations concurrently
* and queue any conflicting operations.
*
* This means that you can submit more than one operation per StackSet and they will be
* executed concurrently. For example you can submit a single request that updates existing
* stack instances *and* creates new stack instances. Any conflicting operations will be queued
* for immediate processing once the conflict is resolved.
*
* @default true
*/
readonly managedExecution?: boolean;
/**
*
*/
readonly operationPreferences?: OperationPreferences;
/**
* Specify a list of capabilities required by your stackset.
*
* StackSets that contains certain functionality require an explicit acknowledgement
* that the stack contains these capabilities.
*
* If you deploy a stack that requires certain capabilities and they are
* not specified, the deployment will fail with a `InsufficientCapabilities` error.
*
* @default - no specific capabilities
*/
readonly capabilities?: Capability[];
}
/**
* Indicates whether a service managed stackset is deployed from the
* AWS Organizations management account or the delegated admin account
*/
enum CallAs {
/**
* The StackSet is deployed from the Delegated Admin account
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-orgs-delegated-admin.html
*/
DELEGATED_ADMIN = 'DELEGATED_ADMIN',
/**
* The StackSet is deployed from the Management account
*/
SELF = 'SELF',
}
/**
* StackSets that contains certain functionality require an explicit acknowledgement
* that the stack contains these capabilities.
*/
export enum Capability {
/**
* Required if the stack contains IAM resources with custom names
*/
NAMED_IAM = 'CAPABILITY_NAMED_IAM',
/**
* Required if the stack contains IAM resources. If the IAM resources
* also have custom names then specify {@link Capability.NAMED_IAM} instead.
*/
IAM = 'CAPABILITY_IAM',
/**
* Required if the stack contains macros. Not supported if deploying
* a service managed stackset.
*/
AUTO_EXPAND = 'CAPABILITY_AUTO_EXPAND',
}
export interface OperationPreferences {
readonly failureToleranceCount?: number;
readonly failureTolerancePercentage?: number;
readonly maxConcurrentCount?: number;
readonly maxConcurrentPercentage?: number;
readonly regionConcurrencyType?: RegionConcurrencyType;
readonly regionOrder?: string[];
}
export enum RegionConcurrencyType {
SEQUENTIAL = 'SEQUENTIAL',
PARALLEL = 'PARALLEL',
}
/**
* Represents a CloudFormation StackSet
*/
export interface IStackSet extends IResource {
/**
* Only available on self managed stacksets.
*
* The admin role that CloudFormation will use to perform stackset operations.
* This role should only have permissions to be assumed by the CloudFormation service
* and to assume the execution role in each individual account.
*
* When you create the execution role it must have an assume role policy statement which
* allows `sts:AssumeRole` from this admin role.
*
* To grant specific users/groups access to use this role to deploy stacksets they must have
* a policy that allows `iam:GetRole` & `iam:PassRole` on this role resource.
*/
readonly role?: iam.IRole;
}
/**
* AWS Regions introduced after March 20, 2019, such as Asia Pacific (Hong Kong), are disabled by default.
* Be aware that to deploy stack instances into a target account that resides in a Region that's disabled by default,
* you will also need to include the regional service principal for that Region.
* Each Region that's disabled by default will have its own regional service principal.
*/
const ENABLED_REGIONS = [
'us-east-1', // US East (N. Virginia)
'eu-west-1', // Europe (Ireland)
'us-west-1', // US West (N. California)
'ap-southeast-1', // Asia Pacific (Singapore)
'ap-northeast-1', // Asia Pacific (Tokyo)
'us-gov-west-1', // AWS GovCloud (US-West)
'us-west-2', // US West (Oregon)
'sa-east-1', // South America (São Paulo)
'ap-southeast-2', // Asia Pacific (Sydney)
'cn-north-1', // China (Beijing)
'eu-central-1', // Europe (Frankfurt)
'ap-northeast-2', // Asia Pacific (Seoul)
'ap-south-1', // Asia Pacific (Mumbai)
'us-east-2', // US East (Ohio)
'ca-central-1', // Canada (Central)
'eu-west-2', // Europe (London)
'cn-northwest-1', // China (Ningxia)
'eu-west-3', // Europe (Paris)
'ap-northeast-3', // Asia Pacific (Osaka)
'us-gov-east-1', // AWS GovCloud (US-East)
'eu-north-1', // Europe (Stockholm)
'eu-south-2', // Europe (Spain)
];
// disabled regions
// 'af-south-1', // Africa (Cape Town)
// 'ap-southeast-3', // Asia Pacific (Jakarta)
// 'ap-east-1', // Asia Pacific (Hong Kong)
// 'eu-south-1', // Europe (Milan)
// 'me-south-1', // Middle East (Bahrain)
export class StackSet extends Resource implements IStackSet {
private readonly stackInstances: cfn.CfnStackSet.StackInstancesProperty[] = [];
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, {}) }),
});
const deploymentTypeConfig = (props.deploymentType ?? DeploymentType.selfManaged())._bind(this);
if (deploymentTypeConfig.permissionsModel === PermissionModel.SELF_MANAGED) {
this._role = deploymentTypeConfig.adminRole ?? new iam.Role(scope, 'AdminRole', {
assumedBy: new iam.ServicePrincipal('cloudformation.amazonaws.com'),
});
this._role.addToPrincipalPolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ['sts:AssumeRole'],
resources: [
`arn:aws:iam::*:role/${deploymentTypeConfig.executionRoleName ?? 'AWSCloudFormationStackSetExecutionRole'}`,
],
}));
}
if (props.capabilities?.includes(Capability.AUTO_EXPAND) && deploymentTypeConfig.permissionsModel === PermissionModel.SERVICE_MANAGED) {
throw new Error('service managed stacksets do not current support the "AUTO_EXPAND" capability');
}
this.permissionModel = deploymentTypeConfig.permissionsModel;
this.addTarget(props.target);
const stackSet = new cfn.CfnStackSet(this, 'Resource', {
autoDeployment: undefinedIfNoKeys({
enabled: deploymentTypeConfig.autoDeployEnabled,
retainStacksOnAccountRemoval: deploymentTypeConfig.autoDeployRetainStacks,
}),
executionRoleName: deploymentTypeConfig.executionRoleName,
administrationRoleArn: this._role?.roleArn,
description: props.description,
managedExecution: {
Active: props.managedExecution ?? true,
},
operationPreferences: undefinedIfNoKeys({
regionConcurrencyType: props.operationPreferences?.regionConcurrencyType,
maxConcurrentPercentage: props.operationPreferences?.maxConcurrentPercentage,
failureTolerancePercentage: props.operationPreferences?.failureTolerancePercentage,
}),
stackSetName: this.physicalName,
capabilities: props.capabilities,
permissionModel: deploymentTypeConfig.permissionsModel,
callAs: deploymentTypeConfig.callAs,
templateUrl: props.template.templateUrl,
stackInstancesGroup: Lazy.any({ produce: () => { return this.stackInstances; } }),
});
// the file asset bucket deployment needs to complete before the stackset can deploy
for (const fileAssetResourceName of fileAssetResourceNames) {
const fileAssetResource = scope.node.tryFindChild(fileAssetResourceName);
fileAssetResource && stackSet.node.addDependency(fileAssetResource);
}
}
public get role(): iam.IRole | undefined {
if (!this._role) {
throw new Error('service managed StackSets do not have an associated role');
}
return this._role;
}
public addTarget(target: StackSetTarget) {
const targetConfig = target._bind(this);
if (this._role && this._role instanceof iam.Role) {
const disabledPrincipals: iam.IPrincipal[] = [];
targetConfig.regions.forEach(region => {
if (!ENABLED_REGIONS.includes(region)) {
disabledPrincipals.push(new iam.ServicePrincipal(`cloudformation.${region}.amazonaws.com`));
}
});
if (disabledPrincipals.length > 0) {
this._role.assumeRolePolicy?.addStatements(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ['sts:AssumeRole'],
principals: disabledPrincipals,
}));
}
}
this.stackInstances.push({
regions: targetConfig.regions,
parameterOverrides: targetConfig.parameterOverrides,
deploymentTargets: {
accounts: targetConfig.accounts,
accountFilterType: this.permissionModel === PermissionModel.SERVICE_MANAGED
? targetConfig.accountFilterType
: undefined, // field not supported for self managed
organizationalUnitIds: targetConfig.organizationalUnits,
},
});
}
}
function undefinedIfNoKeys<A extends Object>(obj: A): A | undefined {
const allUndefined = Object.values(obj).every(val => val === undefined);
return allUndefined ? undefined : obj;
}