aws-cloudformation / cfn-language-discussion

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

Fn::Range intrinsic function that would return a list of Strings, based on integers that are passed to it #148

Open arthurboghossian opened 11 months ago

arthurboghossian commented 11 months ago

Community Note

Tell us about your request

A new Fn::Range intrinsic function, which would take in either 1 or 2 integer parameters, and would return the corresponding range of integers in String format.

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

Have multiple CommaDelimitedList parameters that I would like to reference within the Resources I create in the Fn::ForEach intrinsic function (see example below). If this function exists, can leverage this and the Fn::Length intrinsic function to achieve what I want.

{
  "Fn::Range": [
    "5"
  ]
}

would return ["0", "1", "2", "3", "4"]

{
  "Fn::Range": [
    "4",
    "7"
  ]
}

would return ["4", "5", "6"]

Are you currently working around this issue?

I'd have to define a Mappings section with the corresponding mapping between the list of parameters that would be iterated over, and the other parameter values for the other properties I've defined.

Note: an alternative solution to this could be Item 2 in #118

What is the expected behavior with this new feature

Want to be able to do something like this:

Parameters:
  TopicNameList:
    Type: CommaDelimitedList
    Default: 'A,B,C'
  DisplayNameList:
    Type: CommaDelimitedList
    Default: 'D,E,F'
Resources:
  'Fn::ForEach::Topics':
    - Identifier
    - 'Fn::Range':
        - 'Fn::Length': !Ref TopicNameList
    - Topic${Identifier}:
        Type: AWS::SNS::Topic
        Properties:
          TopicName: !Select [!Ref Identifier, !Ref TopicNameList]
          DisplayName: !Select [!Ref Identifier, !Ref DisplayNameList]
josb commented 11 months ago

Please make them Numbers. Type support in CloudFormation is already poor, let's not make it worse.