CloudFormation -- possible to have nested Mappings?
Faced the same issue. Found the following in the Fn::FindInMap documentation
The intrinsic function Fn::FindInMap returns the value corresponding to keys in a two-level map that is declared in the Mappings section.
So basically:
The following will work:
Mappings:
map_name:
level_1_key:
level_2_key:
"value"
But 3 levels won't.
Mappings:
map_name:
level_1_key:
level_2_key:
level_3_key:
"value"
I ended up doing it like this:
"Mappings" :
{
"dev" :
{
"us-east-1" :
{
"ImageId" : "something",
"Subnet" : "something"
},
"us-west-2" :
{
"ImageId" : "something",
"Subnet" : "something"
}
},
"qa" :
{
"us-east-1" :
{
"ImageId" : "something",
"Subnet" : "something"
},
"us-west-2" :
{
"ImageId" : "something",
"Subnet" : "something"
}
}
}
The important point here is that the objects alternate between "mappings" and keys". So in this situation, "dev" is a Mapping, "us-east-1" is a key, "ImageId" is a mapping, and "something" is a key. Mapping names cannot have non-alphanumeric characters, so Region names cannot be Mappings. Thus, using the environment as the first parameter and using the region name as the second parameter is mandatory.
It seems to me like the Mappings section of CloudFormation has a lot of really strange arbitrary rules, and it surprises me that it isn't more flexible, but there you have it.