-
Notifications
You must be signed in to change notification settings - Fork 16
/
dependency-chain.ts
49 lines (43 loc) · 1.48 KB
/
dependency-chain.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
import { IAspect, Stack } from "aws-cdk-lib";
import { IConstruct } from "constructs";
import { Account } from "./account";
import { DelegatedAdministrator } from "./delegated-administrator";
import { EnableAwsServiceAccess } from "./enable-aws-service-access";
import { EnablePolicyType } from "./enable-policy-type";
import { OrganizationalUnit } from "./organizational-unit";
import { PolicyAttachment } from "./policy-attachment";
/**
* Aspect to create dependency chain of organization resource that needs to be deployed sequentially
* @experimental
*/
export class DependencyChain implements IAspect {
private previous: { [stackName: string]: IConstruct } = {};
visit(current: IConstruct): void {
if (!this.needsChaining(current)) {
return;
}
const stackName = Stack.of(current).stackName;
if (this.previous[stackName]) {
current.node.addDependency(this.previous[stackName]);
}
this.previous[stackName] = current;
}
private needsChaining(current: IConstruct): boolean {
switch (true) {
case current instanceof EnablePolicyType:
return true;
case current instanceof EnableAwsServiceAccess:
return true;
case current instanceof DelegatedAdministrator:
return true;
case current instanceof Account:
return true;
case current instanceof OrganizationalUnit:
return true;
case current instanceof PolicyAttachment:
return true;
default:
return false;
}
}
}