Skip to content

Commit

Permalink
Add ObjectLock as a storage attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
flavianh committed Oct 21, 2021
1 parent 1c2a241 commit 3ca1812
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/constructs/aws/Storage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CfnBucket } from "@aws-cdk/aws-s3";
import { BlockPublicAccess, Bucket, BucketEncryption, StorageClass } from "@aws-cdk/aws-s3";
import type { Construct as CdkConstruct } from "@aws-cdk/core";
import { CfnOutput, Duration, Fn, Stack } from "@aws-cdk/core";
Expand All @@ -14,13 +15,15 @@ const STORAGE_DEFINITION = {
encryption: {
anyOf: [{ const: "s3" }, { const: "kms" }],
},
objectLock: { type: "boolean" },
},
additionalProperties: false,
} as const;
const STORAGE_DEFAULTS: Required<FromSchema<typeof STORAGE_DEFINITION>> = {
type: "storage",
archive: 45,
encryption: "s3",
objectLock: false,
};

type Configuration = FromSchema<typeof STORAGE_DEFINITION>;
Expand Down Expand Up @@ -62,6 +65,12 @@ export class Storage extends AwsConstruct {
],
});

// Until https://github.com/aws/aws-cdk/issues/5247 is resolved
if (resolvedConfiguration.objectLock) {
const cfnBucket = this.bucket.node.defaultChild as CfnBucket;
cfnBucket.addPropertyOverride("ObjectLockConfiguration.ObjectLockEnabled", "Enabled");
}

this.bucketNameOutput = new CfnOutput(this, "BucketName", {
value: this.bucket.bucketName,
});
Expand Down

0 comments on commit 3ca1812

Please sign in to comment.