cloud-custodian icon indicating copy to clipboard operation
cloud-custodian copied to clipboard

core - filters - add value-list filter

Open thisisshi opened this issue 2 years ago • 3 comments

This PR adds a new in-memory filter, value-list which allows you to do a composite filter on elements in a list on the resource without having to fall back on advanced JMESPath expressions:

policies:
  - name: task-def-with-non-registry-images
    resource: aws.ecs-task-definition
    filters:
        - type: value-list
          key: containerDefinitions
          value:
            - not:
              - type: value
                key: image
                value: "${account_id}.dkr.ecr.us-east-2.amazonaws.com.*"
                op: regex

Hat tip @ajkerrigan for the following example:

- type: value
  key: |
    properties.securityRules[?(
      starts_with(properties.sourceAddressPrefix, '1.2.')
      && properties.destinationPortRange == '22'
    )]
  value: not-null

Turns into:

- type: value-list
  key: properties.securityRules[]
  value:
    - type: value
      key: properties.sourceAddressPrefix
      value_type: cidr
      op: in
      value: '1.2.0.0/16'
    - type: value
      key: properties.destinationPortRange
      value_type: integer
      value: 22

thisisshi avatar Sep 07 '22 23:09 thisisshi

@ajkerrigan

  • sounds good, pushed a pr to annotate with c7n:ValueListMatches with the jmespath to the element(s) that matched
  • I dont think there will be a case where key will be something other than a list, if it's a subdict you would be able to just construct the filters with normal value filters, for the name i'm amenable to changes, value-list just happened to be the first name i thought of

thisisshi avatar Sep 08 '22 16:09 thisisshi

thinking on names, was thinking about list-item.. since its about multi attribute on an item in the list, thoughts?

kapilt avatar Sep 09 '22 19:09 kapilt

@kapilt list-item sounds good to me

thisisshi avatar Sep 09 '22 20:09 thisisshi