aws-cloudformation / cfn-lint

CloudFormation Linter
MIT No Attribution
2.4k stars 577 forks source link

YAML anchors & key overrides #2993

Open krystof-k opened 6 months ago

krystof-k commented 6 months ago

Is this feature request related to a new rule or cfn-lint capabilities?

rules

Describe the feature you'd like to request

I'm using YAML anchors like this:

Resources:
  Common:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: ./stack.yaml
      Parameters:
        &CommonParameters
        # Common parameters to be included in the stacks below
        Image: !Ref PG08Image
        # Specific parameters to be overridden in the stacks below
        Name: Common
  Web:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: ./stack.yaml
      Parameters:
        <<: *CommonParameters
        Name: Web

Which results in

E0000 Duplicate found "Name" (line 11)
template.yaml:11:9

Describe the solution you'd like

It would be great if this case (duplicate keys) is a separate rule and can be turned off. Turning of E0000 didn't work for me and I would probably not even want that.

Additional context

No response

Is this something that you'd be interested in working on?

Would this feature include a breaking change?

krystof-k commented 6 months ago

However when I run the lint on the packaged template (aws cloudformation package), it passes fine as the initial values are omitted. So this is not such a huge deal, although having be able to lint the source files would be nice.

kddejong commented 6 months ago

Going to think on this one. One of the issues we have is since we are parsing into a python dict we lose the second key. What this would probably look like is we continue to parse, raise the error and the final object. I think this would be possible