-
Notifications
You must be signed in to change notification settings - Fork 163
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
Call cfn-lint for module fragments #644
Conversation
src/rpdk/core/fragment/generator.py
Outdated
LOG.warning("Module fragment is valid.") | ||
else: | ||
LOG.warning( | ||
"Module fragment is valid, but there are warnings from cfn-lint " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
We don't really know the module fragment is valid yet, right?
-
Worth distinguishing terminology from one of
cfn-lint
s rule levels?
"Module fragment is valid, but there are warnings from cfn-lint " | |
"Module fragment might be valid, but there are warnings from cfn-lint " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this only appear if the user running validate
specifies increased verbosity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PatMyron right. I'll edit both.
@jotompki no, for modules this runs all the time.
Other options like |
src/rpdk/core/fragment/generator.py
Outdated
LOG.warning("Module fragment is valid.") | ||
else: | ||
LOG.warning( | ||
"Module fragment is valid, but there are warnings from cfn-lint " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this only appear if the user running validate
specifies increased verbosity?
with open(filename, "w") as outfile: | ||
json.dump(raw_fragment, outfile, indent=4) | ||
|
||
template = cfnlint.decode.cfn_json.load(filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use the yaml loads() so we don't have to write to a temporary file: https://github.com/aws-cloudformation/cfn-python-lint/blob/master/src/cfnlint/decode/cfn_yaml.py#L183?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that cfnlint.core.run_checks
needs a filename
to run. I haven't seen an api that validates a template in memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is filename being used anywhere?
if it's really necessary recommend: https://docs.python.org/3/library/tempfile.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jotompki yep, it's used by cfnlint.core.run_checks
. I tried using NamedTemporaryFile
, I don't see the benefit, I have to write the file, then read it back, and then manually remove it?
This is great to see. One of the things that may be worth adding as a rule (Warning level) is using parameters in conditions inside your module. Not sure if you would want to add custom rules but I got tripped up on this. |
@kddejong this can be added as an extra validation in RPDK, right? @MalikAtalla-AWS has context on all the validations were are currently doing. |
Issue #, if available: N/A
Description of changes: when calling
cfn validate
on a module, runcfn-lint
on the fragment for extra validations.(Future improvement: support
cfn validate --region
so that we can pass theregion
value tocfn-lint
. Related: aws-cloudformation/cfn-lint#607)Sample output:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.