Skip to content

Raw conditions

For a condition Bylaw's keywords can't express, Condition takes one Azure Policy condition as it would appear in policy JSON, as a hashtable or as JSON text:

When {
    Condition @{ value = '[requestContext().apiVersion]'; greaterOrEquals = '2020-01-01' }
}

Require 'No rule allows SSH from anywhere' {
    Condition -Violation @{
        count   = @{
            field = 'securityRules[*]'
            where = @{ allOf = @(
                    @{ field = 'securityRules[*].sourceAddressPrefix'; equals = '*' }
                    @{ field = 'securityRules[*].destinationPortRange'; equals = '22' }
                ) }
        }
        greater = 0
    }
}
  • In When and Count -Where, it is emitted as written, like everything else there.
  • In Require and Each, statements describe the compliant state and are inverted, which Bylaw can't do correctly for raw JSON. So say which form you wrote: -Violation is the condition that finds a non-compliant resource, emitted as written; -Compliant is the compliant state, emitted as not(...).
  • Field names resolve like Field: a short name against the Resource type, or relative to the element inside Each. A full alias, a path with [*] (as policy JSON writes it inside a count's where), or an ARM expression is used as written. Unknown aliases are still an error.
  • Values can be Param and Arm, so parameters are still declared and checked. Use a [ordered] hashtable, or JSON text, where the order of a literal object's keys matters.
  • In AuditIfNotExists and DeployIfNotExists, Require describes the related resource's compliant state, which Azure's existence condition is, so the forms swap: -Compliant is emitted as written, and -Violation as not(...).
  • Nothing else is checked. Bylaw adds no missing-field handling to a raw condition, and can't tell whether it means what its Require says. Prefer Bylaw's own keywords wherever they can express the condition.