Converting existing policies¶
ConvertTo-Bylaw turns existing policy definitions and initiatives into .bylaw.ps1 files. It reads EPAC definitions, plain { name, properties } JSON, or a properties object on its own, from .json and .jsonc files, folders of them, or the pipeline:
ConvertTo-Bylaw -Path ./Definitions -OutputPath ./policies
Every file is proven before it is written: it is compiled in the input's format (EPAC when the input has a $schema, plain JSON otherwise) and compared with the input by meaning, not text (ADR-0041). A file that can't be proven equivalent isn't written. For example, storage-deny-public-network-access.json converts to:
# Converted from storage-deny-public-network-access.json by ConvertTo-Bylaw.
Policy 'storage-deny-public-network-access' {
Properties @{
DisplayName = 'Storage accounts should disable public network access'
Description = 'Denies storage accounts that allow public network access or allow-all IP rules.'
Version = '1.0.0'
Category = 'Storage'
Mode = 'All'
}
Resource 'Microsoft.Storage/storageAccounts' {
When {
Field kind | Must -BeIn @('StorageV2', 'BlockBlobStorage')
}
Require 'publicNetworkAccess is Disabled' {
Field publicNetworkAccess | Must -Be 'Disabled'
}
Require 'networkAcls.ipRules and value are as required' {
Each 'networkAcls.ipRules[*]' {
Field value | Must -Not -Be '0.0.0.0/0'
}
}
}
Effect Deny
}
- The violation becomes
Requireblocks. The conditions before it areWhen, and each alternative of the violation is aRequire, inverted back into the compliant state, with the missing-field handling recognised so-IfPresentand-Strictcome back where they were. JSON has no descriptions, so aRequireis named after what it tests: rename them to say what they require. - Effects come back as their keywords, with their details:
Modify,Append,DenyAction,Manual,AuditIfNotExistsandDeployIfNotExists, with roles by name where the role map has them. EPAC's generated effect parameter becomes the literal effect, as above, since the EPAC build generates it again. ADeployIfNotExiststemplate is written beside the file, astemplates/<name>.json. - Initiatives become
Initiativefiles. EPAC members referenced by name are written by name, built-in policies by GUID, and any other ID in full. - What Bylaw's keywords can't express is written with
Condition(Raw conditions), and the result's status isEscapeHatchrather thanConverted, with a warning (BYL6005). Check those statements, and replace them as the language grows. - What it can't convert is reported as an error, with a
BYL6xxxcode and the reason, and nothing is written for it; the other definitions still convert. Use-ErrorAction Stopto stop at the first. - Names: a definition without a name, such as a
propertiesfile, is named after its file, with a warning (BYL6008). - Mode: a policy without a
modeis converted asMode = 'Indexed', which is what Azure treats a missing mode as, with a warning (BYL6012).New-AzPolicyDefinitionis the exception: it deploys a definition without a mode asAll. Fields Azure sets,policyTypeandversions, are ignored. - Build warnings: when a converted file compiles with a warning, such as a location check under
Mode = 'All', conversion reports it as BYL6009, with the warning's own code and line, soBuild-Bylawholds no surprises. - Aliases: fields are shortened against the alias snapshot where they resolve back. A type or alias the snapshot lacks is written in full, and the file then builds only with
-AllowUnknownAlias(BYL6007): runUpdate-BylawAliasCachefirst for short names everywhere. - Existing files are left as they are, with a warning (BYL6006), unless
-Forceis given.-WhatIfwrites nothing,-Verboselists the files written, and without-OutputPath, or with-PassThru, each result is returned:Name,Source,Status,Script,Templates,OutputFileandDiagnostics.
Coverage¶
The test suite converts a pinned copy of the Azure Landing Zones Library, at 3ac1ed6 (2026-11-21), and fails if any definition converts worse than its recorded baseline (ADR-0042). Every conversion is proven:
- 149 of 149 policy definitions converted (1 with
Condition) - 44 of 44 initiatives converted
Condition holds what Bylaw's keywords can't express yet. Every conversion is committed in tests/Alz/converted, so you can read what real ALZ policies look like in Bylaw. ./build/alz/Get-AlzCoverage.ps1 writes the full report to out/alz-coverage.md.