You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A .rego file that declares a package and populates a violation set using diagnostic builtins.
Structure
package my_rules
import rego.v1
violation contains v if {
some name, res ininput.resources
res.resourceType =="AWS::S3::Bucket" not res.properties.BucketEncryption
v :=make_diag("CUSTOM001", "ERROR", name, "S3 bucket must have encryption configured")
}
Declare a package.
Import rego.v1.
Add elements to violation using make_diag builtins.
Severity is a string: "FATAL", "ERROR", "WARN", "INFO", "DEBUG". Pass "" for resource_id on template-level diagnostics. Pass "" for optional string args to omit them.
Template Introspection Builtins
Called as bare functions (no namespace prefix). See the rego-engine README for the full list.
Key ones:
Builtin
Purpose
resolve(resource_id, path)
Resolve a property through intrinsics
has_property(resource_id, path)
Check if a property exists
resources_of_type(type)
Get all logical IDs of a resource type
is_dynamic(resource_id, path)
Check if a property is unresolvable
schema_enum(resource_type, prop)
Get allowed enum values
Example
package encryption_rules
import rego.v1
violation contains v if {
some name, res ininput.resources
res.resourceType =="AWS::S3::Bucket" not res.properties.BucketEncryption
v :=make_diag_at("CUSTOM001", "ERROR", name,
"Properties.BucketEncryption",
"S3 bucket must have encryption configured")
}
violation contains v if {
some name, res ininput.resources
res.resourceType =="AWS::Lambda::Function"
res.properties.Runtime =="python3.8"
v :=make_diag_full("CUSTOM002", "WARN", name,
"Properties.Runtime",
"Lambda uses deprecated Python 3.8 runtime",
"Upgrade to python3.12 or later",
"https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html")
}
Guard DSL Rules
CloudFormation Guard declarative rules. Translated internally — works with both RegoEngine and CelEngine.