Option to disable E1029 using a regex pattern on the variable name
See original GitHub issuecfn-lint version: 0.26.0
This is another take on the https://github.com/aws-cloudformation/cfn-python-lint/issues/740. I am using cfn-lint in combination with Serverless Framework and the VSCode plugin to validate the CloudFormation template “chunks” that are referenced in the resource section within the serverless.yml (spec: https://serverless.com/framework/docs/providers/aws/guide/serverless.yml/)
serverless.yml
(not validated by cfn-lint, provided for reference)
service: my-service
provider:
name: aws
[... other stuff ..]
# importing raw CloudFormation files here
resources:
- Description: My Example Service Stack
# roles
- ${file(./cfn-resources/resource1.yml)}
- ${file(./cfn-resources/resource2.yml)}
.cfnlintrc
templates:
- cfn-resources/*.yml
resource1.yml
Conditions:
PrimaryRegion: !Equals ['${self:provider.region}', 'us-east-1']
[some resources]
Serverless framework will pre-process the yml file and replace the ${…} sequence with actual string values before generating the actual CloudFormation template to be sent to AWS. Unfortunately they chose a syntax that conflicts with something CloudFormation uses as well.
With the above config, cfn-lint generates this error:
E1029: Found an embedded parameter outside of an "Fn::Sub" at Conditions/PrimaryRegion/Fn::Equals/0
I can get around this error by putting a !Sub in front of it (which is useless, it will upload an unnecessary !Sub ‘us-east-1’ to AWS). But then I get this:
E1019: Parameter self:provider.region for Fn::Sub not found at Conditions/PrimaryRegion/Fn::Equals/0/Fn::Sub
So I have to disable both rules, or disable E1019 and stick a !Sub in front of everything that has a serverless-specific variable.
It would be great to have a way to be able to configure both rules in such a way that they treat the whole ${variable}
block as a literal by if variable
matches a regex pattern. Ideally through .cfnlintrc so it applies to all the files…
NOTE: I am aware that this is not an issue with cfn-python-lint, but I don’t see how it could be solved by the VSCode plugin (it basically reports what it gets from cfn-lint) or the Serverless team (they’re stuck with the syntax due to backwards compatibility, it’s been discussed before, in the context of having the problem in the opposite direction by serverless treating ${AWS::Region} as its own variable and trying to replace it, see https://github.com/serverless/serverless/pull/3694)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
I installed 0.28.1 and it works as intended, we can close this.
I think this could be done easily. Configuring this rule seems to be never ending so making it a little more dynamic seems like a reasonable approach to me.