Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fn::FindInMap support Fn conditions #79

Closed
cmckni3 opened this issue May 21, 2020 · 6 comments
Closed

Fn::FindInMap support Fn conditions #79

cmckni3 opened this issue May 21, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@cmckni3
Copy link

cmckni3 commented May 21, 2020

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...)
@cmckni3
Copy link
Author

cmckni3 commented May 21, 2020

Feel free to adjust/make more generic than supporting condition functions. I can think of some possible use cases for Fn::Sub as well.

@luiseduardocolon luiseduardocolon added the enhancement New feature or request label May 29, 2020
@jk2l
Copy link

jk2l commented Jun 3, 2020

@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
Copy link
Author

cmckni3 commented Jun 3, 2020

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

@wayne-folkes
Copy link

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"

@lejiati
Copy link
Contributor

lejiati commented May 25, 2022

@cmckni3 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
Copy link
Contributor

lejiati commented Jan 27, 2023

Thank you for your feedback! Fn::FindInMap now supports additional intrinsic functions including Fn::If. You can find more details in official docs.

@lejiati lejiati closed this as completed Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants