Cloudformation-coverage-roadmap: Fn::FindInMap support Fn conditions

Created on 21 May 2020  路  4Comments  路  Source: aws-cloudformation/cloudformation-coverage-roadmap

Currently Fn::FindInMap function only supports Fn::FindInMap and Ref.

2. Scope of request

e) other coverage-related issue with the resource/attribute/option

3. Expected behavior

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.

4. Suggest specific test cases

Fn::FindInMap:
  - DNS
  - !If ["HasSpecialDNS", !Ref country, "default" ]
  - "dns"

5. Helpful Links to speed up research and evaluation

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html#w2ab1c25c28c26c13

https://stackoverflow.com/questions/35904204/default-value-on-mappings-aws-cloudformation

6. Category (required) - Will help with tagging and be easier to find by other users to +1

Use the categories as displayed in the AWS Management Console (simplified):

  1. Management (CloudTrail, Config...)
enhancement

Most helpful comment

@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.

All 4 comments

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"

Was this page helpful?
0 / 5 - 0 ratings