Skip to content

Fn.conditionOr generates invalid CFN snippet #25696

@MalikAtalla-AWS

Description

@MalikAtalla-AWS

Describe the bug

I have a piece of code that uses Fn.conditionOr with a list of conditions. When the list is longer than 10 elements, CDK is smart enough to break it up into chunks of 10. Otherwise, CloudFormation would complain that an Fn::Or cannot have more than 10 elements. The problem I'm running into is for a list of 11 elements. CDK generates two Fn::Or expressions: One with 10 elements and one with 1 element. When deployment this stack, CloudFormation complains that an Fn::Or must contain at least 2 elements.
Error message from CFN: Template error: every Fn::Or object requires a list of at least 2 and at most 10 boolean parameters.

Expected Behavior

Given a list of conditions of length 11 (let's say of type Fn::Equals) and this code snippet:
Fn.conditionOr(...conditions), CDK should break up the list in a way that's valid according to CloudFormation's rules. For example into length 9 and 2:

"Fn::Or": [
 {
  "Fn::Or": [
   {
    "Fn::Equals": [
     "1",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "2",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "3",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "4",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "5",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "6",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "7",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "8",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "9",
     "B"
    ]
   }
  ]
 },
 {
  "Fn::Or": [
   {
    "Fn::Equals": [
     "10",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "11",
     "B"
    ]
   }
  ]
 }
]

Current Behavior

Given a list of conditions of length 11 (let's say of type Fn::Equals) and this code snippet:
Fn.conditionOr(...conditions), CDK generates a template snippet like this:

"Fn::Or": [
 {
  "Fn::Or": [
   {
    "Fn::Equals": [
     "1",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "2",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "3",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "4",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "5",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "6",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "7",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "8",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "9",
     "B"
    ]
   },
   {
    "Fn::Equals": [
     "10",
     "B"
    ]
   }
  ]
 },
 {
  "Fn::Or": [
   {
    "Fn::Equals": [
     "11",
     "B"
    ]
   }
  ]
 }
]

Reproduction Steps

See example above

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.62.2

Framework Version

No response

Node.js Version

v16.20.0

OS

Ubuntu 20

Language

Typescript

Language Version

4.9.4

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-cloudformationRelated to AWS CloudFormationbugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions