Currently Fn::FindInMap function only supports Fn::FindInMap and Ref.
e) other coverage-related issue with the resource/attribute/option
Should be able use condition functions such as Fn::If. This can help specify a default key in the map. Currently Fn::If is not supported so trying to use a default key in a map results in an error stating the key was not found in the mapping.
Fn::FindInMap:
- DNS
- !If ["HasSpecialDNS", !Ref country, "default" ]
- "dns"
https://stackoverflow.com/questions/35904204/default-value-on-mappings-aws-cloudformation
Use the categories as displayed in the AWS Management Console (simplified):
Feel free to adjust/make more generic than supporting condition functions. I can think of some possible use cases for Fn::Sub as well.
@cmckni3 while this may not quite exactly what you want. you can do this the other way round
Fn::If:
- HasSpecialDNS
- !FindInMap [ DNS, !Ref country, "dns"]
- !FindInMap [ DNS, "default", "dns"]
also if country is Cfn parameter, you can set DefaultValue as "default"
@cmckni3 while this may not quite exactly what you want. you can do this the other way round
Fn::If: - HasSpecialDNS - !FindInMap [ DNS, !Ref country, "dns"] - !FindInMap [ DNS, "default", "dns"]also if country is Cfn parameter, you can set DefaultValue as "default"
@jk21 I am aware and ended up with something similar. In my case, I would have preferred to not specify a default/use NoValue.
In my use case this did not work for me Cloudformation does not validate the template if the item does not exist in map even if you intend to use the "default" value.
I want to take some conditional action based on account ID if the account condition is true use the value in the map for that account if false use the default. Even through the condition is evaluated properly the CF validator wants you to have a mapping for the account.
@cmckni3 while this may not quite exactly what you want. you can do this the other way round
Fn::If: - HasSpecialDNS - !FindInMap [ DNS, !Ref country, "dns"] - !FindInMap [ DNS, "default", "dns"]also if country is Cfn parameter, you can set DefaultValue as "default"
Most helpful comment
@jk21 I am aware and ended up with something similar. In my case, I would have preferred to not specify a default/use
NoValue.