aws-cloudformation / cfn-language-discussion

Language discussions for CloudFormation template language
https://aws.amazon.com/cloudformation/
Apache License 2.0
143 stars 13 forks source link

Add Fn::Filter to complement Fn::Select #121

Open josb opened 1 year ago

josb commented 1 year ago

Community Note

Tell us about your request

Fn::Reject intrinsic function.

Tell us about the problem you are trying to solve. What are you trying to do, and why is it hard?

Right now one has to use Fn::Transform to e.g. remove a part of a CommanDelimitedList parameter.

Today's use case was a parameter named BucketARNs with the contents

arn:%{AWSPartition}:s3:::foo,
arn:%{AWSPartition}:s3:::foo/*,
NONE

To be able to pass this to !Ref, the NONE needed to be removed.

Are you currently working around this issue?

By using a Ruby Fn::Transform macro.

What is the expect behavior with this new feature

Code:

Resource: !Reject [ NONE, !Ref BucketARNs ]

Returns:

arn:%{AWSPartition}:s3:::foo,
arn:%{AWSPartition}:s3:::foo/*

Additional context

None.

Attachments

None.

benkehoe commented 1 year ago

This is useful, but I don't like the name. When I saw the issue title, I thought it might be a way to have a condition that invalidates the template (which is an interesting idea!). I'd go for Fn::Remove or something like that.

benbridts commented 1 year ago

I think I'd prefer something like

Fn::Filter:
  - !Ref BucketARNs
  - $Item != NONE
josb commented 1 year ago

Honestly I am not picky about the name/syntax, I picked Reject for symmetry with Select and because in Ruby there are reject and select methods that are complimentary. Filter would be fine, too, and access to the Item looks like a useful enhancement.