Repository: cloud-custodian/cloud-custodian

Issue:
aws.cloudtrail - tag filter
Objective: I want to write a policy to identify all cloud trails with missing tags. Currently it does not support this.


Discussion:

Resolving patch:
diff --git a/c7n/resources/cloudtrail.py b/c7n/resources/cloudtrail.py
--- a/c7n/resources/cloudtrail.py
+++ b/c7n/resources/cloudtrail.py
@@ -19,7 +19,8 @@
 from c7n.exceptions import PolicyValidationError
 from c7n.filters import ValueFilter, Filter
 from c7n.manager import resources
-from c7n.query import QueryResourceManager, TypeInfo
+from c7n.tags import universal_augment
+from c7n.query import DescribeSource, QueryResourceManager, TypeInfo
 from c7n.utils import local_session, type_schema
 
 from .aws import shape_validate, Arn
@@ -38,6 +39,18 @@ class resource_type(TypeInfo):
         arn = id = 'TrailARN'
         name = 'Name'
         config_type = "AWS::CloudTrail::Trail"
+        universal_taggable = object()
+
+    def get_source(self, source_type):
+        if source_type == 'describe':
+            return DescribeTrail(self)
+        return super(CloudTrail, self).get_source(source_type)
+
+
+class DescribeTrail(DescribeSource):
+
+    def augment(self, resources):
+        return universal_augment(self.manager, resources)
 
 
 @CloudTrail.filter_registry.register('is-shadow')


Test patch:
diff --git a/tests/data/placebo/test_account_data_events/tagging.GetResources_1.json b/tests/data/placebo/test_account_data_events/tagging.GetResources_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_account_data_events/tagging.GetResources_1.json
@@ -0,0 +1 @@
+{"status_code": 200, "data": {"ResourceTagMappingList": []}}
diff --git a/tests/data/placebo/test_cloudtrail_delete/tagging.GetResources_1.json b/tests/data/placebo/test_cloudtrail_delete/tagging.GetResources_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_cloudtrail_delete/tagging.GetResources_1.json
@@ -0,0 +1 @@
+{"status_code": 200, "data": {"ResourceTagMappingList": []}}
diff --git a/tests/data/placebo/test_cloudtrail_is_shadow/tagging.GetResources_1.json b/tests/data/placebo/test_cloudtrail_is_shadow/tagging.GetResources_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_cloudtrail_is_shadow/tagging.GetResources_1.json
@@ -0,0 +1 @@
+{"status_code": 200, "data": {"ResourceTagMappingList": []}}
diff --git a/tests/data/placebo/test_cloudtrail_is_shadow_or_not/tagging.GetResources_1.json b/tests/data/placebo/test_cloudtrail_is_shadow_or_not/tagging.GetResources_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_cloudtrail_is_shadow_or_not/tagging.GetResources_1.json
@@ -0,0 +1 @@
+{"status_code": 200, "data": {"ResourceTagMappingList": []}}
diff --git a/tests/data/placebo/test_cloudtrail_resource_with_not_filter/tagging.GetResources_1.json b/tests/data/placebo/test_cloudtrail_resource_with_not_filter/tagging.GetResources_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_cloudtrail_resource_with_not_filter/tagging.GetResources_1.json
@@ -0,0 +1 @@
+{"status_code": 200, "data": {"ResourceTagMappingList": []}}
diff --git a/tests/data/placebo/test_cloudtrail_set_logging/tagging.GetResources_1.json b/tests/data/placebo/test_cloudtrail_set_logging/tagging.GetResources_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_cloudtrail_set_logging/tagging.GetResources_1.json
@@ -0,0 +1 @@
+{"status_code": 200, "data": {"ResourceTagMappingList": []}}
diff --git a/tests/data/placebo/test_cloudtrail_status/tagging.GetResources_1.json b/tests/data/placebo/test_cloudtrail_status/tagging.GetResources_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_cloudtrail_status/tagging.GetResources_1.json
@@ -0,0 +1 @@
+{"status_code": 200, "data": {"ResourceTagMappingList": []}}
diff --git a/tests/data/placebo/test_cloudtrail_update/tagging.GetResources_1.json b/tests/data/placebo/test_cloudtrail_update/tagging.GetResources_1.json
new file mode 100644
--- /dev/null
+++ b/tests/data/placebo/test_cloudtrail_update/tagging.GetResources_1.json
@@ -0,0 +1 @@
+{"status_code": 200, "data": {"ResourceTagMappingList": []}}