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::ForEach could not be resolved when values array references Map using AccountId key #3747

Closed
nosnilmot opened this issue Oct 15, 2024 · 1 comment · Fixed by #3749
Closed

Comments

@nosnilmot
Copy link

nosnilmot commented Oct 15, 2024

CloudFormation Lint Version

cfn-lint 1.16.1 / git v1.16.1-5-g07652d4a4

What operating system are you using?

Mac

Describe the bug

cfn-lint fails to resolve Fn::ForEach when values array comes from Map with AccountId key

$ cfn-lint mapt.yaml 
E0001 Error transforming template: Fn::ForEach could not be resolved
mapt.yaml:11:7

Expected behavior

cfn-lint passes

Reproduction template

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::LanguageExtensions
Mappings:
  AccountMap:
    12345678901:
      Emails:
        - [email protected]
Resources:
  'Fn::ForEach::Subscriptions':
    - Email
    - !FindInMap [AccountMap, !Ref AWS::AccountId, Emails]
    - 'SubscriptionFor&{Email}':
        Type: AWS::SNS::Subscription
        Properties:
          TopicArn: "arn:aws:sns:us-east-1:12345678901:my-sns-topic"
          Protocol: email
          Endpoint: !Ref Email
@nosnilmot
Copy link
Author

Still fails if the found list is empty. Does this need a new issue?

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::LanguageExtensions
Mappings:
  AccountMap:
    '012345678901':
      Emails: []
Resources:
  'Fn::ForEach::Subscriptions':
    - Email
    - !FindInMap [AccountMap, !Ref AWS::AccountId, Emails]
    - 'SubscriptionFor&{Email}':
        Type: AWS::SNS::Subscription
        Properties:
          TopicArn: "arn:aws:sns:us-east-1:012345678901:my-sns-topic"
          Protocol: email
          Endpoint: !Ref Email
$ cfn-lint map3747.yaml 
E0001 Error transforming template: Fn::ForEach could not be resolved
map3747.yaml:10:7

It only fails if first map entry has empty list, i.e. this also fails:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::LanguageExtensions
Mappings:
  AccountMap:
    '012345678901':
      Emails: []
    '123456789012':
      Emails:
        - [email protected]
Resources:
  'Fn::ForEach::Subscriptions':
    - Email
    - !FindInMap [AccountMap, !Ref AWS::AccountId, Emails]
    - 'SubscriptionFor&{Email}':
        Type: AWS::SNS::Subscription
        Properties:
          TopicArn: "arn:aws:sns:us-east-1:012345678901:my-sns-topic"
          Protocol: email
          Endpoint: !Ref Email
$ cfn-lint map3747.yaml 
E0001 Error transforming template: Fn::ForEach could not be resolved
map3747.yaml:13:7

But ths passes:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::LanguageExtensions
Mappings:
  AccountMap:
    '123456789012':
      Emails:
        - [email protected]
    '012345678901':
      Emails: []
Resources:
  'Fn::ForEach::Subscriptions':
    - Email
    - !FindInMap [AccountMap, !Ref AWS::AccountId, Emails]
    - 'SubscriptionFor&{Email}':
        Type: AWS::SNS::Subscription
        Properties:
          TopicArn: "arn:aws:sns:us-east-1:012345678901:my-sns-topic"
          Protocol: email
          Endpoint: !Ref Email
$ cfn-lint map3747.yaml 
$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant