Skip to content

Bylaw

Bylaw is a PowerShell module for writing Azure Policy in a Pester-style language. You describe what a compliant resource looks like, and Bylaw compiles that into Azure Policy definition JSON, for any tool that deploys policy definitions, including Enterprise Policy as Code (EPAC).

Policy 'storage-require-tls12' {

    Properties @{
        DisplayName = 'Storage accounts should require TLS 1.2'
        Category    = 'Storage'
        Version     = '1.0.0'
        Mode        = 'Indexed'
    }

    Resource 'Microsoft.Storage/storageAccounts' {
        Require 'TLS 1.2 or later' {
            Field minimumTlsVersion | Must -Be 'TLS1_2'
        }
    }

    Effect Deny
}

Install

Bylaw needs PowerShell 7.2 or later, on Windows, Linux or macOS. Compiling needs no Azure modules and no Azure connection. It is a prerelease, so it needs -Prerelease:

Install-PSResource -Name Bylaw -Prerelease

Compiling a policy file runs it

A .bylaw.ps1 file is a PowerShell script, and Build-Bylaw runs it with your permissions. Each file runs in its own runspace, but that is not a security sandbox. Don't build files you don't trust. In CI, don't run Build-Bylaw on pull requests from forks with access to secrets.

This documentation

These pages describe the version of Bylaw shown at the top of the page; choose another there.

  • Guide: writing policies, operators and missing fields, counts, effects, initiatives, converting existing policies, building and testing.
  • Reference: the commands, every keyword, and every diagnostic code with what it means and how to fix it.
  • Decisions: the architecture decision records, with the reasoning behind the language and the compiler.