Can FindInMap return a list?
Solution 1:
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.
Solution 2:
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
orList
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]