cfn-language-discussion
cfn-language-discussion copied to clipboard
Add Fn::Sequence Intrinsic Function to AWS CloudFormation for Dynamic Sequence Generation
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Tell us about your request
I'd like to propose the addition of a new intrinsic function, Fn::Sequence
, to AWS CloudFormation.
Tell us about the problem you are trying to solve. What are you trying to do, and why is it hard?
In many CloudFormation templates, there's a frequent need to generate sequences of strings, numbers, or other patterns, especially when provisioning a set of similar resources. For instance, when setting up an etcd cluster, I might need to generate sequential endpoint URLs. Without a native sequence function, users are forced to hardcode sequences or use cumbersome workarounds. This function would streamline the creation of such sequences, thereby making templates more concise and easier to maintain.
The impact of not having this problem solved is the increased complexity in CloudFormation templates and a higher potential for manual errors.
Are you currently working around this issue?
Currently, this is typically solved using iterative methods in the programming/scripting languages or manual hardcoding in the CloudFormation templates. Both approaches are error-prone and don't promote reusability and dynamic template generation.
What is the expected behavior with this new feature
With the new Fn::Sequence
function, users can specify a starting point, an ending point, an optional step increment, and a format string. The function would then return a list of strings that follow the defined pattern.
Example:
Parameters:
NumberOfNodes:
Type: Number
Default: 2
Resources:
MyResource:
Type: "AWS::SomeResource"
Properties:
SomeProperty:
Fn::Join:
- ","
-
Fn::Sequence:
- Start: 1
End: !Ref NumberOfNodes
Step: 1
Format: "etcd${Value}=http://etcd${Value}:2380"
Expected Output: ["etcd1=http://etcd1:2380", "etcd2=http://etcd2:2380"]
This function would be especially useful in conjunction with Fn::ForEach
, allowing for more dynamic and scalable templates.
Additional context
Such functionality exists in various forms in other infrastructure-as-code or scripting tools. Having a similar capability in CloudFormation would bridge the feature gap and reduce the need to rely on external tools or Lambda-backed custom resources just to generate sequences.