Skip to content

BYL6xxx: Conversion

Reported by ConvertTo-Bylaw while it converts policy definition JSON into .bylaw.ps1 files. Every converted file is compiled and compared with its input before it is written, so a definition that can't be converted exactly is reported, not written.

Code Severity Meaning
BYL6001 Error Input isn't a policy definition
BYL6002 Error Definition can't be converted
BYL6003 Error Conversion failed
BYL6004 Error Converted file isn't equivalent
BYL6005 Warning Converted with raw conditions
BYL6006 Warning Output file already exists
BYL6007 Warning Type or alias not in the alias snapshot
BYL6008 Warning Definition named after its file
BYL6009 Warning The converted file compiles with a warning
BYL6010 Warning Initiative member named by ConvertTo-Bylaw
BYL6011 Error Two definitions would write the same file
BYL6012 Warning Policy with no mode converted as Indexed

BYL6001

Input isn't a policy definition (error)

The input isn't valid JSON, or isn't a JSON object. ConvertTo-Bylaw reads EPAC definitions, plain { name, properties } JSON, or a properties object, from .json and .jsonc files or the pipeline. A bare policy rule ({ if, then }), a parameters map, or a list of an initiative's members or groups, such as Community-Policy's azurepolicy.rules.json, azurepolicy.parameters.json, azurepolicyset.definitions.json and azurepolicyset.groups.json, is only part of a definition, and an ARM deployment template, such as one ConvertTo-Bylaw writes to templates, isn't a definition: each is skipped when found in a folder or piped from Get-ChildItem, and reported when given on its own.

To fix it: Check the file is a single policy definition. Comments and trailing commas are allowed, as in EPAC's .jsonc files. For a file that is part of a definition, convert the full definition it comes from, such as the azurepolicy.json or azurepolicyset.json beside it. For a deployment template, convert the policy that deploys it.

See ADR-0039.

BYL6002

Definition can't be converted (error)

The definition uses something this version of ConvertTo-Bylaw doesn't convert, or that Bylaw's keywords can't write: a resource provider mode, an effect parameter it doesn't declare, effect details of an unknown shape, a DenyAction other than delete, a Modify operation other than addOrReplace, add or remove, a Modify or DeployIfNotExists without roles, a deployment with a template link or a mode other than incremental, or in an initiative a member or group with properties Bylaw doesn't write, a group with a display name, category or description in EPAC (which its schema doesn't allow), or policyDefinitionName in plain JSON. Also a top-level version in EPAC, whose schemas don't have it (ADR-0016) and a deployment parameter passed as something other than a value or a Key Vault reference. The message says which.

To fix it: Write the policy in Bylaw by hand for now, using the JSON as a guide. Later versions convert more.

See ADR-0039.

BYL6003

Conversion failed (error)

ConvertTo-Bylaw failed while converting the definition, or the file it wrote for it doesn't compile. That's a bug in ConvertTo-Bylaw, not in your definition, so nothing was written.

To fix it: Report it with the definition, if you can share it. The message has the error, or the first compile errors.

See ADR-0039.

BYL6004

Converted file isn't equivalent (error)

The converted file compiles, but its output couldn't be proven to mean the same as the input, so it wasn't written. The comparison never reports equivalence wrongly, but it can fail to prove it, for example when two conditions are related in a way it treats as independent (ADR-0041). The message gives the first differences.

To fix it: Check the differences in the message. If they are real, report them as a ConvertTo-Bylaw bug; if not, write the policy by hand.

See ADR-0041.

BYL6005

Converted with raw conditions (warning)

Some conditions can't be written with Bylaw's keywords, so they are written as raw JSON with Condition (ADR-0040). The file is still proven equivalent to its input.

To fix it: Check the Condition statements. Replace them with Bylaw's own statements where they can express them, which gives you its missing-field handling and checks.

See ADR-0040.

BYL6006

Output file already exists (warning)

A .bylaw.ps1 file with the definition's name is already in the output folder, so it was left as it is, in case it has been edited.

To fix it: Use -Force to replace it, or convert into another folder.

See ADR-0039.

BYL6007

Type or alias not in the alias snapshot (warning)

The definition uses a resource type or alias that isn't in the alias snapshot: its own type, a related type, or a field, including one in a Condition. Those fields are written as full aliases, with -AllowUnknownAlias where Field takes it, and the file builds only with Build-Bylaw -AllowUnknownAlias. The bundled snapshot has every type as of the module's release; Update-BylawAliasCache gets types Azure has added since.

To fix it: Refresh the snapshot with Update-BylawAliasCache, then convert again to get short field names.

See ADR-0008.

BYL6008

Definition named after its file (warning)

The definition has no name, as when a file holds only the properties object, so it is named after its file: the part of the file name before the first dot. The name is the definition's identity in Azure and its output file name, so renaming it later creates a new definition.

To fix it: Check the name in the converted file's Policy line, and change it there if it isn't the one you deploy the definition with.

See ADR-0010.

BYL6009

The converted file compiles with a warning (warning)

The converted file compiles, and is proven equivalent to its input, but Build-Bylaw will warn about it: the definition does something Bylaw advises against, such as a location check under Mode All (BYL3040), or a DeployIfNotExists on its own resource type without the resource's name (BYL3090). The message gives the warning's own code and the line in the converted file.

To fix it: Look up the code the message names, and decide whether to change the definition. The conversion itself is correct.

See ADR-0039.

BYL6010

Initiative member named by ConvertTo-Bylaw (warning)

An initiative member has no policyDefinitionReferenceId. Azure generates one when it's left out, but Bylaw always writes one, so the member is named after its policy: the policy's name, or the last part of its definition ID (the GUID, for a built-in policy), with -2, -3 and so on when that is taken. The reference ID is how an assignment's non-compliance messages, an exemption, and remediation refer to a member, so a different one in a deployed initiative breaks those references.

To fix it: If the initiative isn't deployed yet, keep the names or change -ReferenceId to something readable. If it is, set -ReferenceId to the ID Azure gave each member, from the deployed initiative's policyDefinitions (Get-AzPolicySetDefinition, or az policy set-definition show).

See ADR-0039.

BYL6011

Two definitions would write the same file (error)

Two inputs convert to definitions with the same name in the same output folder, so both would be written to one .bylaw.ps1 file. The first is written, and the others aren't. This happens when a folder holds two copies of one definition, such as files built from it, or files written by an earlier run.

To fix it: Convert only one copy: remove the others from the input, or give -Path the folders to convert. If the definitions are different, give them different names.

See ADR-0039.

BYL6012

Policy with no mode converted as Indexed (warning)

The policy definition has no mode. Azure documents that a null mode is the same as Indexed, so the converted file sets Mode = 'Indexed', and the compiled definition is equivalent to the input. Bylaw writes Indexed because its own default, when Mode is left out, is All. Azure PowerShell's New-AzPolicyDefinition is the exception: it sets the mode to All when the definition has none, so a definition deployed that way is All in Azure. Many built-in policies, such as the Microsoft Managed Control policies, have no mode.

To fix it: Nothing, if the definition was deployed with the Azure CLI, an ARM or Bicep template, EPAC or the REST API. If it was deployed with New-AzPolicyDefinition, check its mode in Azure, and set Mode = 'All' if that is what it has.

See ADR-0039.