Repository: cdklabs/cdk-enterprise-iac (language: python)

Issue:
feat: Add Aspect to remove S3 PublicAccessBlockConfiguration
[PublicAccessBlockConfiguration](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html#cfn-s3-bucket-publicaccessblockconfiguration) isn't supported as a Cloudformation property in all AWS regions.

Give the option for users to remove this property from the synthesized cloudformation


Discussion / hints:

Fix patch:
diff --git a/API.md b/API.md
index 407fa61..8705be2 100644
--- a/API.md
+++ b/API.md
@@ -212,6 +212,52 @@ All aspects can visit an IConstruct.
 
 
 
+### RemovePublicAccessBlockConfiguration <a name="RemovePublicAccessBlockConfiguration" id="@cdklabs/cdk-enterprise-iac.RemovePublicAccessBlockConfiguration"></a>
+
+- *Implements:* aws-cdk-lib.IAspect
+
+Looks for S3 Buckets, and removes the `PublicAccessBlockConfiguration` property.
+
+For use in regions where Cloudformation doesn't support this property
+
+#### Initializers <a name="Initializers" id="@cdklabs/cdk-enterprise-iac.RemovePublicAccessBlockConfiguration.Initializer"></a>
+
+```typescript
+import { RemovePublicAccessBlockConfiguration } from '@cdklabs/cdk-enterprise-iac'
+
+new RemovePublicAccessBlockConfiguration()
+```
+
+| **Name** | **Type** | **Description** |
+| --- | --- | --- |
+
+---
+
+#### Methods <a name="Methods" id="Methods"></a>
+
+| **Name** | **Description** |
+| --- | --- |
+| <code><a href="#@cdklabs/cdk-enterprise-iac.RemovePublicAccessBlockConfiguration.visit">visit</a></code> | All aspects can visit an IConstruct. |
+
+---
+
+##### `visit` <a name="visit" id="@cdklabs/cdk-enterprise-iac.RemovePublicAccessBlockConfiguration.visit"></a>
+
+```typescript
+public visit(node: IConstruct): void
+```
+
+All aspects can visit an IConstruct.
+
+###### `node`<sup>Required</sup> <a name="node" id="@cdklabs/cdk-enterprise-iac.RemovePublicAccessBlockConfiguration.visit.parameter.node"></a>
+
+- *Type:* constructs.IConstruct
+
+---
+
+
+
+
 ### RemoveTags <a name="RemoveTags" id="@cdklabs/cdk-enterprise-iac.RemoveTags"></a>
 
 - *Implements:* aws-cdk-lib.IAspect
diff --git a/src/index.ts b/src/index.ts
index 4df6b26..50815ba 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -4,3 +4,4 @@ SPDX-License-Identifier: Apache-2.0
 */
 export * from './patches/addPermissionsBoundary';
 export * from './patches/removeTags';
+export * from './patches/removePublicAccessBlockConfiguration';
diff --git a/src/patches/removePublicAccessBlockConfiguration.ts b/src/patches/removePublicAccessBlockConfiguration.ts
new file mode 100644
index 0000000..1c092e1
--- /dev/null
+++ b/src/patches/removePublicAccessBlockConfiguration.ts
@@ -0,0 +1,21 @@
+/*
+Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+SPDX-License-Identifier: Apache-2.0
+*/
+import { IAspect } from 'aws-cdk-lib';
+import { Bucket, CfnBucket } from 'aws-cdk-lib/aws-s3';
+import { IConstruct } from 'constructs';
+
+/**
+ * Looks for S3 Buckets, and removes the `PublicAccessBlockConfiguration` property.
+ *
+ * For use in regions where Cloudformation doesn't support this property
+ */
+export class RemovePublicAccessBlockConfiguration implements IAspect {
+  public visit(node: IConstruct): void {
+    if (node instanceof Bucket) {
+      const cfnBucket = node.node.defaultChild as CfnBucket;
+      cfnBucket.addPropertyDeletionOverride('PublicAccessBlockConfiguration');
+    }
+  }
+}


Test patch:
diff --git a/test/patches/removePublicAccessBlockConfiguration.test.ts b/test/patches/removePublicAccessBlockConfiguration.test.ts
new file mode 100644
index 0000000..800d52d
--- /dev/null
+++ b/test/patches/removePublicAccessBlockConfiguration.test.ts
@@ -0,0 +1,29 @@
+/*
+Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+SPDX-License-Identifier: Apache-2.0
+*/
+import { Aspects, Stack } from 'aws-cdk-lib';
+import { Match, Template } from 'aws-cdk-lib/assertions';
+import { BlockPublicAccess, Bucket } from 'aws-cdk-lib/aws-s3';
+import { RemovePublicAccessBlockConfiguration } from '../../src/patches/removePublicAccessBlockConfiguration';
+
+let stack: Stack;
+
+beforeEach(() => {
+  stack = new Stack();
+});
+
+describe('Removal of PublicAccessBlockConfiguration', () => {
+  test('Removes PublicAccessBlockConfiguration from S3 bucket', () => {
+    new Bucket(stack, 'MyBucket', {
+      blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
+    });
+
+    Aspects.of(stack).add(new RemovePublicAccessBlockConfiguration());
+
+    const template = Template.fromStack(stack);
+    template.hasResourceProperties('AWS::S3::Bucket', {
+      PublicAccessBlockConfiguration: Match.absent(),
+    });
+  });
+});