Repository: cloud-custodian/cloud-custodian

Issue:
aws - event bus delete action
### Describe the feature

Delete action for event-bus

### Extra information or context

_No response_


Discussion:

Resolving patch:
diff --git a/c7n/resources/cw.py b/c7n/resources/cw.py
--- a/c7n/resources/cw.py
+++ b/c7n/resources/cw.py
@@ -161,6 +161,36 @@ class resource_type(TypeInfo):
 class EventBusCrossAccountFilter(CrossAccountAccessFilter):
     # dummy permission
     permissions = ('events:ListEventBuses',)
+    
+@EventBus.action_registry.register('delete')
+class EventBusDelete(BaseAction):
+    """Delete an event bus.
+
+    :example:
+
+    .. code-block:: yaml
+
+            policies:
+              - name: cloudwatch-delete-event-bus
+                resource: aws.event-bus
+                filters:
+                    - Name: test-event-bus
+                actions:
+                  - delete
+    """
+
+    schema = type_schema('delete')
+    permissions = ('events:DeleteEventBus',)
+
+    def process(self, resources):
+        client = local_session(
+            self.manager.session_factory).client('events')
+
+        for resource_set in chunks(resources, size=100):
+            for r in resource_set:
+                self.manager.retry(
+                    client.delete_event_bus,
+                    Name=r['Name'])
 
 
 @resources.register('event-rule')


Test patch:
diff --git a/tests/data/placebo/test_event_bus_delete/events.DeleteEventBus_1.json b/tests/data/placebo/test_event_bus_delete/events.DeleteEventBus_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_event_bus_delete/events.DeleteEventBus_1.json
@@ -0,0 +1,6 @@
+{
+    "status_code": 200,
+    "data": {
+        "ResponseMetadata": {}
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_event_bus_delete/events.ListEventBuses_1.json b/tests/data/placebo/test_event_bus_delete/events.ListEventBuses_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_event_bus_delete/events.ListEventBuses_1.json
@@ -0,0 +1,16 @@
+{
+    "status_code": 200,
+    "data": {
+        "EventBuses": [
+            {
+                "Name": "default",
+                "Arn": "arn:aws:events:us-east-1:644160558196:event-bus/default"
+            },
+            {
+                "Name": "test-event-bus",
+                "Arn": "arn:aws:events:us-east-1:644160558196:event-bus/test-event-bus"
+            }
+        ],
+        "ResponseMetadata": {}
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_event_bus_delete/events.ListEventBuses_2.json b/tests/data/placebo/test_event_bus_delete/events.ListEventBuses_2.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_event_bus_delete/events.ListEventBuses_2.json
@@ -0,0 +1,12 @@
+{
+    "status_code": 200,
+    "data": {
+        "EventBuses": [
+            {
+                "Name": "default",
+                "Arn": "arn:aws:events:us-east-1:644160558196:event-bus/default"
+            }
+        ],
+        "ResponseMetadata": {}
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_event_bus_delete/tagging.GetResources_1.json b/tests/data/placebo/test_event_bus_delete/tagging.GetResources_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_event_bus_delete/tagging.GetResources_1.json
@@ -0,0 +1,22 @@
+{
+    "status_code": 200,
+    "data": {
+        "PaginationToken": "",
+        "ResourceTagMappingList": [
+            {
+                "ResourceARN": "arn:aws:events:us-east-1:644160558196:event-bus/default",
+                "Tags": [
+                    {
+                        "Key": "Env",
+                        "Value": "Default"
+                    }
+                ]
+            },
+            {
+                "ResourceARN": "arn:aws:events:us-east-1:644160558196:event-bus/test-event-bus",
+                "Tags": []
+            }
+        ],
+        "ResponseMetadata": {}
+    }
+}
\ No newline at end of file
diff --git a/tests/test_cwe.py b/tests/test_cwe.py
--- a/tests/test_cwe.py
+++ b/tests/test_cwe.py
@@ -336,3 +336,26 @@ def test_cloud_trail_resource(self):
             json.dumps(matched_event, sort_keys=True, cls=JmespathEncoder),
             json.dumps(expected_event, sort_keys=True, cls=JmespathEncoder),
         )
+
+class EventBusTest(BaseTest):
+    def test_event_bus_delete(self):
+        factory = self.replay_flight_data("test_event_bus_delete")
+        p = self.load_policy(
+            {
+                "name": "delete-event-bus",
+                "resource": "event-bus",
+                "filters": [{"Name": "test-event-bus"}],
+                "actions": ["delete"],
+            },
+            session_factory=factory,
+        )
+        resources = p.run()
+        self.assertEqual(len(resources), 1)
+        self.assertEqual(
+            sorted([r["Name"] for r in resources]),
+            ["test-event-bus"],
+        )
+        client = factory().client("events")
+        remainder = client.list_event_buses()["EventBuses"]
+        self.assertEqual(len(remainder), 1)
+        self.assertNotEqual(remainder[0]["Name"], "test-event-bus")