cloudformation-guard icon indicating copy to clipboard operation
cloudformation-guard copied to clipboard

`cfn-guard validate -o json` does not include `CDK-Path`

Open alexpulver opened this issue 2 years ago • 3 comments

I see CDK-Path in text output, but don't see when using-o json.

By the way, should there be a difference between --print-json and -o json? Why not have only -o json?

Command

cfn-guard validate -d template.json -r rules.guard -o json > output.json

template.json

{
  "Resources": {
    "WebsiteBucket4326D7C2": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "AccessControl": "PublicRead"
      },
      "Metadata": {
        "aws:cdk:path": "LandingPageFrontend/Website/Bucket/Resource"
      }
    }
  }
}

rules.guard

let aws_s3_bucket_resources = Resources.*[ Type == 'AWS::S3::Bucket' ]

rule aws_s3_bucket_versioning_defined {
  when %aws_s3_bucket_resources not empty {
    %aws_s3_bucket_resources {
      Properties {
        VersioningConfiguration exists <<VersioningConfiguration is not defined>>
      }
    }
  }
}

Originally posted by @alexpulver in https://github.com/aws-cloudformation/cloudformation-guard/issues/204#issuecomment-1171957925

alexpulver avatar Jul 01 '22 05:07 alexpulver

Noted @alexpulver Will bring this back to the team.

razcloud avatar Jul 05 '22 16:07 razcloud

--print-json is supposed to print JSON for abstract syntax tree for the clauses in the rule, which tells us more details about how the clauses get evaluated.

-o json just changes the format of output summary that's emitted for failures, with error message from the rule, if any.

We will keep this issue opened, and make the --help docs less ambiguous.

akshayrane avatar Jul 11 '22 22:07 akshayrane

Thank you!

alexpulver avatar Jul 12 '22 14:07 alexpulver

Hey @alexpulver due to work required to add this, and it leading to possibly a breaking change with existing consumers of the JSON output we have chosen to not add this to the current JSON output.

Thanks,

joshfried-aws avatar Apr 18 '24 20:04 joshfried-aws