Skip to content

Plain definition JSON is the default output, with EPAC one setting away, one file per policy

Context and Problem Statement

Bylaw's output has to be consumed by a deployment tool. Which format is the default, how are files laid out, and how will new formats be added?

Bylaw is for anyone writing Azure Policy, not only EPAC users. Most tools that deploy definitions, such as New-AzPolicyDefinition, the Azure CLI, Bicep, Terraform and the portal, take plain definition JSON, and that is also the format Azure publishes built-in definitions in and most published policies use. EPAC has its own file format, which is plain definition JSON with a $schema, validated against a schema that is stricter than Azure (ADR-0023).

Decision Drivers

  • Someone trying Bylaw gets a valid Azure Policy definition of what they wrote, with no errors or generated content that Azure itself doesn't need.
  • An EPAC project gets EPAC files without passing -Format on every build.
  • The output drops into the folder the deployment tool reads.

Considered Options

  • Plain definition JSON as the default, with EPAC chosen by -Format or in bylaw.json
  • The EPAC definition file format as the default, with plain definition JSON as a second emitter
  • Plain ARM definition JSON only
  • Bicep only

Decision Outcome

Chosen option: "Plain definition JSON as the default, with EPAC chosen by -Format or in bylaw.json", because it serves every tool, emits the policy as written, and costs an EPAC project one line of settings.

Until 0.6.0-alpha, EPAC was the default. It was the first target, and its output drops straight into an EPAC Definitions/policyDefinitions folder. It was changed because the EPAC schema's rules fell on everyone, not only EPAC users: a policy without Category or Version failed the default build (BYL4001, BYL4002), though Azure needs neither; a literal effect became a generated parameter; and a literal or Arm effect was refused (amended 2026-11-30).

Choosing the format

The format is the first of:

  1. Build-Bylaw -Format Epac or -Format PlainJson.
  2. format in bylaw.json (ADR-0012): "Epac" or "PlainJson". An EPAC project sets it once, usually beside initiativeOutputPath (ADR-0035).
  3. PlainJson.

ConvertTo-Bylaw isn't affected: it proves each conversion in its input's format (ADR-0041).

Plain JSON (-Format PlainJson, the default)

The layout Azure publishes built-in definitions in, { "name", "properties" }, with the policy emitted as written. ADR-0027 describes it.

EPAC (-Format Epac)

{
  "$schema": "https://raw.githubusercontent.com/Azure/enterprise-azure-policy-as-code/main/Schemas/policy-definition-schema.json",
  "name": "storage-deny-public-network-access",
  "properties": {
    "displayName": "...",
    "mode": "All",
    "description": "...",
    "metadata": { "version": "1.0.0", "category": "Storage" },
    "parameters": { "effect": { ... } },
    "policyRule": { "if": { ... }, "then": { ... } }
  }
}

(The canonical writer expands the objects shown inline here, per ADR-0009.)

  • $schema is always included, so editors validate the file against the EPAC schema.
  • What the EPAC schema requires and Azure doesn't is generated where it can be, and an error where only the author knows it, such as the category (ADR-0023).
  • policyType is never emitted. Azure sets it, to Custom for every definition a user creates, and EPAC's policy definition schema doesn't list it. Until 0.5.0-alpha it was written as Custom, as in the EPAC template; it was dropped because hand-written definitions, such as Azure Community Policy's, leave it out, so converting one and building it back added it (added 2026-11-30).
  • id is never emitted, because EPAC ignores it.
  • metadata.deployedBy is never emitted. EPAC adds it at deploy time, and setting it in the file overrides EPAC's value.
  • Where the effect is parameterised, EPAC recommends naming the parameter effect (see ADR-0018).

Layout

  • One file per policy, named <name>.json. Initiatives can be written to a folder of their own, as EPAC needs (ADR-0035).
  • The output mirrors the source folder structure: <Path>/storage/a.bylaw.ps1 writes its policies to <OutputPath>/storage/<name>.json. A file that contains several policies writes them side by side in the mirrored folder.
  • Bylaw never deletes files in -OutputPath. Cleaning up stale output is left to the user, and Bylaw warns about *.json files in the output folder that no source file produced.

Emitter design

Emitters implement a common contract: Name, FileExtension, and Emit(PolicyNode) -> ordered document. The canonical writer turns the document into bytes. The emitters are PlainJson (ADR-0027) and Epac. Bicep may follow later. A Bicep emitter that writes text can implement the same contract but bypass the JSON writer.

Consequences

  • Good, because the default output is a valid definition for any tool, and is the policy as written.
  • Good, because a newcomer meets only the language's own errors, not EPAC's schema rules.
  • Good, because an EPAC project still gets files that drop into Definitions/policyDefinitions, with one setting.
  • Good, because mirroring the folder structure keeps the author's organisation of their policies.
  • Bad, because changing the default in 0.6.0-alpha changes the output of a build that relied on it. A project that wants EPAC adds "format": "Epac" to bylaw.json, or passes -Format Epac.
  • Bad, because a plain JSON initiative that includes policies from the build needs definitionScope, to give each a full ID, where EPAC resolves them by name (ADR-0035). Building a first initiative now meets that error unless the project sets a scope or chooses EPAC; the error says which.
  • Bad, because the EPAC $schema URL points at EPAC's main branch. If EPAC moves it, we change it and regenerate the golden files.

Confirmation

  • Each golden folder names its format in tests/Golden/GoldenRoots.psd1, so the golden tests don't depend on the default.
  • EPAC golden files are validated against the EPAC JSON schema in CI, using a pinned copy of the schema in tests/, and plain JSON golden files against the structure ADR-0027 describes.
  • Unit tests cover the order of precedence: -Format over format in bylaw.json over the default, and an unknown format failing the build.

More Information