Skip to content

Commit e225c35

Browse files
authored
added prep to secrets container (#1164)
1 parent 37ccc29 commit e225c35

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/lib/cdk-accelerator/src/core/secrets-container.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class SecretsContainer extends Construct {
4949

5050
constructor(scope: Construct, name: string) {
5151
super(scope, name);
52-
52+
cdk.Aspects.of(this).add({ visit: () => this.prep() });
5353
this.keyAlias = createEncryptionKeyName(`Secrets-Key`);
5454
this.encryptionKey = new kms.Key(this, `EncryptionKey`, {
5555
alias: `alias/${this.keyAlias}`,
@@ -80,16 +80,6 @@ export class SecretsContainer extends Construct {
8080
},
8181
}),
8282
);
83-
84-
if (this.principals.length) {
85-
this.encryptionKey.addToResourcePolicy(
86-
new iam.PolicyStatement({
87-
actions: ['kms:Decrypt'],
88-
resources: ['*'],
89-
principals: this.principals,
90-
}),
91-
);
92-
}
9383
}
9484

9585
/**
@@ -116,4 +106,14 @@ export class SecretsContainer extends Construct {
116106
get alias() {
117107
return this.keyAlias;
118108
}
109+
110+
protected prep(): void {
111+
this.encryptionKey.addToResourcePolicy(
112+
new iam.PolicyStatement({
113+
actions: ['kms:Decrypt'],
114+
resources: ['*'],
115+
principals: this.principals,
116+
}),
117+
);
118+
}
119119
}

0 commit comments

Comments
 (0)