Conforming to the EPAC policy definition schema¶
Context and Problem Statement¶
The spec's definition of done says Build-Bylaw produces EPAC-valid JSON, and ADR-0011 says golden files are validated against the EPAC schema. The EPAC policy definition schema (JSON Schema 2020-12, checked 2026-11-25) is stricter than Azure itself:
| EPAC schema rule | Azure |
|---|---|
properties requires displayName, mode, metadata, parameters, policyRule |
only policyRule is required |
metadata requires version and category |
optional |
then.effect must be the exact string [parameters('effect')] |
any effect, literal or expression |
a parameter named effect requires type String, metadata.displayName exactly Effect, allowedValues with at least 2 unique effects, and defaultValue |
defaultValue is optional, and so is allowedValues |
every parameter requires metadata.displayName |
optional |
parameter type is one of String, Array, Object, Boolean, Integer, Float |
DateTime is also valid |
How should Bylaw's EPAC emitter handle these differences?
Decision Drivers¶
- Output from
-Format Epacpasses the EPAC schema, so editors and CI raise no errors. - Authors don't write boilerplate that the compiler can generate (spec: "Generated boilerplate for effect parameters and metadata").
- No silent guesses about content that only the author knows, such as the category.
- The policy layer of the IR stays format-neutral. EPAC rules live in the EPAC emitter, so the plain JSON emitter (ADR-0027) isn't bound by them.
Considered Options¶
- Generate what can be derived, and fail the EPAC build for what can't
- Emit as written and warn where the output breaks the schema
- Make every EPAC rule part of the language, for every format
Decision Outcome¶
Chosen option: "Generate what can be derived, and fail the EPAC build for what can't". The EPAC emitter checks a policy before it emits it, and reports BYL4xxx diagnostics with the source location.
Generated:
metadataandparametersare always emitted, as{}when they are empty.- A literal effect becomes an effect parameter.
Effect Denyemitsthen.effect: "[parameters('effect')]"and this parameter:
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"defaultValue": "Deny"
}
For Effect, the allowed values are Audit, Deny and Disabled. For a keyword in place of Effect, they are its own effect and Disabled, as built-in policies use, for example Modify and Disabled (ADR-0017). The default is the literal effect, so the policy behaves as written unless an assignment overrides it. The parameter is added after the declared parameters. The description is the text Azure built-in policies use.
* A declared effect parameter (Effect (Param Effect)) gets metadata.displayName Effect, and the same description unless the author sets one.
* Any other parameter without a DisplayName gets one from its name, split into words in sentence case: AllowedLocations becomes Allowed locations and TLSVersion becomes TLS version.
Errors:
BYL4001:Categoryis not set. There is no sensible default.BYL4002:Versionis not set. A default of1.0.0would be easy, but versioning is the author's call, and silently versioning every policy1.0.0hides the omission.BYL4003: the effect parameter's JSON name isn'teffect, for example becauseJsonNameis set to something else.BYL4004: the effect parameter has noDefault.BYL4005: the effect parameter has fewer than 2 distinctAllowedValues.BYL4006: the effect parameter has aDisplayNameother thanEffect.BYL4007: the effect is a literal, but a parameter with the JSON nameeffectis already declared. The author should useEffect (Param Effect).BYL4008: the effect is anArmexpression, which the schema doesn't allow.
Warnings:
BYL4009: a parameter of typeDateTime. Azure accepts it but the EPAC schema doesn't list it. The policy still compiles, because it deploys.BYL4010: anAppendpolicy. Azure requires its details to be an array, but the EPAC schema saysdetailsis an object. The policy still compiles, because it deploys (ADR-0029).
Consequences¶
- Good, because every definition from
-Format Epacpasses the EPAC schema, which CI checks for the golden files. - Good, because
Effect Denystays the simplest thing to write, and the output still matches EPAC's convention. - Bad, because a literal effect is no longer fixed: an assignment can change it. Plain JSON output emits literal effects as written (ADR-0027).
- Bad, because
CategoryandVersionare now required for EPAC output, which ADR-0016 lists as optional. - Neutral: the EPAC schema follows EPAC's
mainbranch. A copy is pinned intests/Schemas/and refreshed deliberately, as ADR-0011 says.
Confirmation¶
Unit tests cover each generated element and each BYL4xxx code. Golden files are checked against the pinned schema with Test-Json.
Pros and Cons of the Options¶
Generate and fail¶
- Good, because the output is always schema-valid, with the least boilerplate for authors.
- Bad, because EPAC output needs two Properties keys that other formats won't need.
Emit and warn¶
- Good, because it never blocks a build.
- Bad, because the definition of done (EPAC-valid output) isn't guaranteed, and warnings get ignored.
EPAC rules in the language¶
- Good, because there is one set of rules.
- Bad, because EPAC's conventions would constrain the Plain JSON and Bicep formats too.
More Information¶
- ADR-0011 (EPAC default output), ADR-0016 (Properties), ADR-0017 (effects), ADR-0018 (parameter casing).
- EPAC policy definitions