aws-cloudformation / cfn-lint

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

Fn::Sub warning on Resources line #3440

Open peterneave opened 3 days ago

peterneave commented 3 days ago

CloudFormation Lint Version

1.4.2

What operating system are you using?

Windows, Ububunu

Describe the bug

I'm getting this warning from cfn-lint (1.30 to 1.4.2). - 0.87 is fine by the way. The problem is that it's for the Resources: line section.

W1020 'Fn::Sub' isn't needed because there are no variables
src\project\project.yml:115:1

There are only two places where Fn::Sub is getting used in the whole file and I've checked them. I also checked !Sub references and from what I can see, they look fine too. Obviously having the actual line number that I should be looking at would make a big difference rather than the parent.

I won't include a template as it would be 4k lines. I'm sorry I can't be more specific about this issue as it's kind of vague in of itself.

Expected behavior

I would expect to be directed to the exact line that it's warning me about - not the parent.

Reproduction template

Resources:
  ...
kddejong commented 3 days ago

Any chance you have the resource/property you are using the sub?

I'll look into why the path is getting messed up.

That rule will look for the ${}(with a negative look ahead for the escape characters) pattern in the Fn::Sub string section to validate if there are any parameters. Can you double check that there are variables there. Its possible that the regex is getting tripped on something but I don't believe this regex was changed from v0.

Also are you using SAM in this template? If you are using SAM this would make a little sense as sometimes the newly created resources don't get mapped back correctly.

kddejong commented 3 days ago

This is the regex by the way. re.compile(r"\${([^!].*?)}")

peterneave commented 3 days ago

It is a SAM template. There are two AWS::CloudWatch::Dashboard's that use Fn::Sub and even if I remove those logical resources from the template, it still brings up the warning (i.e there is no Fn::Sub found in the file at all). That is what is odd about it.

kddejong commented 3 days ago

By the time we do validation all occurrences of !Sub are converted into Fn::Sub