Closed alexpulver closed 2 years ago
Thanks for the bug report @alexpulver. The metadata is just appended information for CDK. The error message still displays
Clause(Clause(Location[file:LandingPageFrontend.guard, line:7, column:9], Check: VersioningConfiguration EXISTS ), FAIL)
| From: Map((Path("/Resources/WebsiteBucket4326D7C2/Properties"), MapValue { keys: [], values: {} }))
| Message: VersioningConfiguration is not defined
VersioningConfiguration is not defined, but also appends CDK data. Would you prefer that be optional?
Thanks for clarifying @dchakrav-github! I wasn't sure if Guard appended the AWS CDK metadata purposefully or accidentally. The message formatting is a bit too verbose - contains Guard internal structure instead of a string. Also, having that metadata not as part of the error message would be helpful. That's what mainly caused me to think it's a bug, as I included nothing in the error message to have this appear. I saw your comment on #204 - if you think that approach makes sense; I think it would be preferable to the current behavior.
Error Message [VersioningConfiguration is not defined;Metadata: [String((Path("/Resources/WebsiteBucket4326D7C2/Metadata/aws:cdk:path"), "LandingPageFrontend/Website/Bucket/Resource"))]]
Please check out the Guard 2.1.0 Release that should resolve this issue.
Thanks @razcloud! It looks great now.
P.S.: There seems to be a space missing after the "Message" string, but it's a minor thing 😃 .
$ cfn-guard validate -d template.json -r rules.guard
template.json Status = FAIL
FAILED rules
rules.guard/aws_s3_bucket_versioning_defined FAIL
---
Evaluating data template.json against rules rules.guard
Number of non-compliant resources 1
Resource = WebsiteBucket4326D7C2 {
Type = AWS::S3::Bucket
CDK-Path = LandingPageFrontend/Website/Bucket/Resource
Rule = aws_s3_bucket_versioning_defined {
ALL {
Check = VersioningConfiguration EXISTS {
Message= VersioningConfiguration is not defined
RequiredPropertyError {
PropertyPath = /Resources/WebsiteBucket4326D7C2/Properties[L:5,C:20]
MissingProperty = VersioningConfiguration
Reason = Could not find key VersioningConfiguration inside struct at path /Resources/WebsiteBucket4326D7C2/Properties[L:5,C:20]
Code:
3. "WebsiteBucket4326D7C2": {
4. "Type": "AWS::S3::Bucket",
5. "Properties": {
6. "AccessControl": "PublicRead"
7. },
8. "Metadata": {
}
}
}
}
}
@alexpulver Thank you for letting us know about that! Will have that corrected.
Describe the bug When adding a custom error message,
cfn-guard
also prints details of unrelated resource from the data.To Reproduce Please supply:
LandingPageFrontend.guard
LandingPageFrontend.template.json
-v
log level if it's not related to cfn-guard-lambda, or the relevant CloudWatch log messages if it is related to the cfn-guard-lambdaNOTE: Please be sure that the templates, rules and logs you provide as part of your bug report do not contain any sensitive information.
Expected behavior A clear and concise description of what you expected to happen.
If I remove the
Metadata
resource from the template, I get a clean failure message, without the additional details. That is the expected behavior ifMetadata
would be in the template.Operating System: [eg, MacOS, Windows, Ubuntu, etc]
macOS
OS Version [eg Catalina, 10, 18.04, etc]
Catalina 10.15.7
Additional context Add any other context about the problem here.