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 Throws "E0001 Error Transforming Template: Duplicate Type while doing transformation" When Used in Resources Section #3888

Closed
jbq2 opened this issue Dec 20, 2024 · 2 comments
Labels
question Further information is requested

Comments

@jbq2
Copy link

jbq2 commented Dec 20, 2024

cfn-lint 1.18.4

The following snippet shows something similar to what I am attempting to do (hiding exact details of course):

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::LanguageExtensions'
...
Resources:
  Fn::ForEach::Loop:
    - Id
    - - A
      - B
      - C
    - ScheduleGroup${Id}:
      Type: AWS::Scheduler::ScheduleGroup    # <--- complains about this
      Properties:
        Name: !Ref Id
        ...

When I run this through cfn-lint, the linter is complaining that there is a Duplicate Type while doing transformation, specifically highlighting the Type field under ScheduleGroup${Id}. I believe I have followed the examples in AWS docs properly, specifically the 'Replicate Multiple Resources` of this article. I expect that the for each loop expands to the following template after the transformation is performed:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::LanguageExtensions'
...
Resources:
  ScheduleGroupA:
    Type: AWS::Scheduler::ScheduleGroup
    Properties:
      Name: A
      ...
  ScheduleGroupB:
    Type: AWS::Scheduler::ScheduleGroup
    Properties:
      Name: B
      ...
  ScheduleGroupB:
    Type: AWS::Scheduler::ScheduleGroup
    Properties:
      Name: B
      ...

Am I using Fn::ForEach correctly? Or is this an issue with cfn-lint itself? Unfortunately in my situation, I cannot bypass cfn-lint and force the deployment of these resources.

@jbq2 jbq2 added the question Further information is requested label Dec 20, 2024
@kddejong
Copy link
Contributor

Your indentation is off.

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::LanguageExtensions'
...
Resources:
  Fn::ForEach::Loop:
    - Id
    - - A
      - B
      - C
    - ScheduleGroup${Id}:
        Type: AWS::Scheduler::ScheduleGroup
        Properties:
          Name: !Ref Id
          ...

@jbq2
Copy link
Author

jbq2 commented Jan 4, 2025

Hi @kddejong, thank you for noticing. I actually figured it out at work and forgot to close the issue--apologies

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

No branches or pull requests

2 participants