I'm using CloudFormation to deploy an ELB to a pre-existing VPC which has pre-existing Subnets. I've listed the subnets in a Mappings section of the template and select the mapping based on the Environment parameter. This works fine if the Mapping is for a single value, but I want the Mapping to return a list as I want the ELB to be multi-AZ. I've tried various combinations of the example below, but I always get the same error Value of property Subnets must be of type List of String. Is there a way that FindInMap can return a list of values?

Example ELB Config

"ElasticLoadBalancerAPI": {
            "Properties": {
                "ConnectionDrainingPolicy": {
                    "Enabled": true,
                    "Timeout": 30
                },
                "ConnectionSettings": {
                    "IdleTimeout": 60
                },
                "CrossZone": "false",
                "Subnets" : [
                    {
                        "Fn::FindInMap": [
                            "AWSEnv2PublicSubnets",
                            {
                                "Ref": "Env"
                            },
                            "subList"
                        ]
                    }
                ],
                "SecurityGroups" : [ { "Ref" : "LoadBalancerSecurityGroup" }],
etc...

Example Parameters

"Parameters": {
  "Env": {
            "Description": "Environment",
            "Type": "String",
            "Default": "DEV",
            "AllowedValues": [
                "DEV",
                "TEST"
            ]
        }
}

Example Mappings

"Mappings": {
  "AWSEnv2PublicSubnets": {
            "DEV": {
                "subList": ["subnet-1111","subnet-2222","subnet-3333"]
            },
            "TEST": {
                "subList": ["subnet-4444"]
            }
        }
}

Using the Split function works:

JSON

"Mappings": {
   "AWSEnv2PublicSubnets": {
        "DEV": {
            "subList": "subnet-1111,subnet-2222,subnet-3333"
        }
    }
}

then:

"Subnets" : { 
  "Fn::Split" : [
    ",", 
    { "Fn::FindInMap": [
      "AWSEnv2PublicSubnets",
      { "Ref": "Env" },
      "subList"
    ] }
  ]
}

YAML

Mappings: 
  AWSEnv2PublicSubnets:
    DEV:
      subList: subnet-1111,subnet-2222,subnet-3333

then:

Subnets: !Split [",", !FindInMap [ AWSEnv2PublicSubnets, !Ref Env, subList] ]

I used a comma (,) as my separator character, but you can use anything you want so long as it's not also used as a part of the value.


I think Mappings value supports List type (at least as of now).

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html

The Mappings section consists of the key name Mappings. The keys in mappings must be literal strings. The values can be String or List types.

Here is the example written in YAML.

Parameters:
  Env:
    Type: String
    AllowedValues: [dev, qa, prod]

Mappings:
  Environment:
    dev:
      Groups:
        - Developer
        - QA
    qa:
      Groups:
        - Developer
        - QA
    prod:
      Groups:
        - Operations

Resources:
  Policy:
    Type: AWS::IAM::ManagedPolicy
    Properties:
      ManagedPolicyName: iam-manage-role
      PolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Action:
              - iam:*Role*
            Resource: "*"
      Groups: !FindInMap [Environment, !Ref Env, Groups]