Condition support for "contains" operation
2. Scope of request
Conditions and Fn::If have an exact-equals operation (Fn::Equals) but no way to check whether a value is contained in a list.
This limitation can be worked around if the list is hard-coded by stringing together a list of Fn::Equals with Fn::Or, but this workaround can be cumbersome and does not work if the list is provided as a parameter.
3. Expected behavior
There is a new Fn::Contains condition that can be used in Conditions and in Fn::If. The new condition has the syntax
"Fn::Contains": [ "value_1", [ "value_1", "value_2"... ] ]
and evaluates to true if the first parameter is present in the list provided as the second parameter, or evaluates to false otherwise.
4. Suggest specific test cases
Example: Condition is true if stack region is in a hard-coded list
"Conditions": {
"shouldDeploy": {
"Fn::Contains": [ { "Ref": "AWS::Region" }, ["ca-central-1", "us-east-2"] ]
}
}
Example: Condition is true if stack region is in a list provided as a parameter
"Parameters" : {
"supportedRegions": {
"Description": "Comma-delimited list of supported regions",
"Type": "CommaDelimitedList",
"Default": "ca-central-1, us-east-2"
}
}
"Conditions": {
"shouldDeploy": {
"Fn::Contains": [ { "Ref": "AWS::Region" }, { "Ref": "supportedRegions" } ]
}
}
Example: Condition is false if stack region is not in a hard-coded list
"Conditions": {
"shouldDeploy": {
"Fn::Contains": [ { "Ref": "AWS::Region" }, ["my-kitchen"] ]
}
}
5. Helpful Links to speed up research and evaluation
Mentioned in Twitter here.
6. Category (required) - Will help with tagging and be easier to find by other users to +1
This is a request for a new intrinsic function in the CloudFormation syntax.
- Management (CloudTrail, Config...)
@glb Thank you very much for your feedback! Since this repository is focused on resource coverage, I'm transferring this issue over to a new GitHub repository dedicated to CloudFormation template language issues.