cfn-language-discussion icon indicating copy to clipboard operation
cfn-language-discussion copied to clipboard

FindInMap defaulting

Open ohshazbot opened this issue 3 years ago • 3 comments

Name of the resource

Other

Resource name

Mappings

Description

Mappings provide a great tool for configuration, easing the ability to reuse cloudformation templates across a variety of regions & partitions. However, there is a shortcoming with Mappings as they're only accessible via FindInMap which only works if you know the exact keys and if they're present. If I have a low-traction point of configurability, I need to declare every single permutation, even if it's identical in 99% of cases and if I add support for another domain, like a new region, I need to update the cfn mapping to add the new field. I would like to request either an additional function or an extension of FindInMap which allows defaulting behavior, so if a given tuple is not found in the Mapping, we get the default value instead of the template erroring due to an inability to get mapping.

An alternative solution which would support this use case would be function(s) that enable me to set up If conditions based on key existence in Mappings. So something like

!If
- !MappingPresent [Mapping, 'foo', 'bar']
- !FindInMap [Mapping, 'foo', 'bar']
- 'MyDefaultValue'

Other Details

This has been asked about several times on SO, but I see no historical requests for this feature, not sure if this hasn't been considered or if it has been discussed under a more abstract feature set

ohshazbot avatar Oct 18 '21 15:10 ohshazbot

Related to aws-cloudformation/cfn-language-discussion#79

mikecee avatar Mar 04 '22 15:03 mikecee

@ohshazbot Thank you very much for your feedback! Since this repository is focused on resource coverage, I'm transferring this issue over to a new GitHub repository dedicated to CloudFormation template language issues.

lejiati avatar May 10 '22 02:05 lejiati

Hey @ohshazbot , we have a new RFC https://github.com/aws-cloudformation/cfn-language-discussion/pull/91 proposed to enhance Fn::FindInMap, we invite you to have your input there as well.

lejiati avatar Aug 30 '22 18:08 lejiati

Thank you for the feedback! We have launched this feature as part of the FindInMap enhancement:

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

jtting-amazon avatar Jan 11 '23 21:01 jtting-amazon