hashicorp / terraform-cdk

Define infrastructure resources using programming constructs and provision them using HashiCorp Terraform
https://www.terraform.io/cdktf
Mozilla Public License 2.0
4.85k stars 450 forks source link

Add support for inline comments compatible with tools like checkov #3609

Open woutervb opened 5 months ago

woutervb commented 5 months ago

Description

When running checkov over the generated tf file(s), it's sometimes needed to skip certain checks. This normally can be done by inserting a comment line like: #checkov:skip:CKV2_AWS_62:No need for notifications at strategic locations in the file.

For the aws-cdk, cloudformation, the trick is to add lines like:

bucket.add_override("//", {
            "checkov": {
                "skip": [
                    {"id": "CKV2_AWS_62",
                        "comment": "No need for notifications"
                    }
                ]
            }
        })

Using this code in the terraform cdk, does inject the lines, but checkov does ignore them.

If the terraform code is generated with the --hcl flag, then the added override is completely ignored.

So, I'm basically asking for a way to insert skips for checkov tests that works both with either version of the synth.

References

No response

Help Wanted

Community Note

woutervb commented 5 months ago

This is also discussed on the cdk.dev slack channel https://cdk-dev.slack.com/archives/C017XMM5L7N/p1714518985544069