The cfn-guard cli includes commands to experiment with cloudformation-guard rules locally. To use the tool specifically for Config rule testing:
- Create
rule.guard
with your rule code - Create
resource.json
with a Config resource json to evaluate against (you can copy this from a resource in the Config console) - Use the
cfn-guard validate
command to show which rules PASS and which FAIL
cfn-guard validate -r ./rule.guard -d ./resource.json --verbose
There is also a unit testing framework in Guard that uses a rule.guard
file and a test.yml
file specifying your tests. Here is a short test.yml
example:
# test.yml
- name: TagsTest
input:
# `input` is a yaml-formatted, trimmed-down version of a Config resource.
# We only care about the `.tags` top-level property in this test case.
tags:
Owner: austin
Environment: qa
expectations:
rules:
tags_Application_exists: PASS # PASS | FAIL
tags_Application: PASS
tags_Owner_exists: PASS
tags_Owner: PASS
tags_Environment_exists: PASS
tags_Environment: PASS
Use the cfn-guard test
to execute your tests to show which rules are passing and which are failing:
cfn-guard test --rules-file ./rule.guard --test-data ./test.yml --verbose