Skip to content

BYL2xxx: Aliases

Reported while field names are resolved to Azure Policy aliases, using the bundled alias snapshot or one refreshed with Update-BylawAliasCache, and when the alias snapshot or role map is loaded.

Code Severity Meaning
BYL2001 Error Alias not in the snapshot
BYL2002 Error Field matches more than one alias
BYL2003 Error Resource type not in the snapshot
BYL2004 Error Short field name under Resource *
BYL2005 Error Array field with [*] outside Each
BYL2006 Warning Unknown alias used because of -AllowUnknownAlias
BYL2010 Error Alias snapshot can't be read
BYL2020 Error Role map can't be read

BYL2001

Alias not in the snapshot (error)

Azure Policy only evaluates fields through aliases, and an alias that doesn't exist is silently never matched, so the policy would never find a violation. Bylaw checks every field against its alias snapshot. The message suggests the closest alias of the resource type. A property named like a reserved field, such as an extension's own type, can only be reached by its full alias, because the name on its own (type) is the reserved field. A short name that ends in one, such as extensions.type, gets that full alias as its suggestion.

To fix it: Correct the field name. If the alias is newer than the snapshot, refresh it with Update-BylawAliasCache, or use Field -AllowUnknownAlias (or Build-Bylaw -AllowUnknownAlias) to accept it with a warning.

See ADR-0008.

BYL2002

Field matches more than one alias (error)

A short field name is resolved by matching the end of the resource type's aliases, and this one matched several, for example two properties with the same name in different places. Bylaw doesn't guess which one you meant.

To fix it: Use the full alias, or enough of its path to match only one. The message lists the candidates.

For example:

Field 'Microsoft.Storage/storageAccounts/networkAcls.defaultAction' | Must -Be 'Deny'

BYL2003

Resource type not in the snapshot (error)

The Resource type, or the -Type of AuditIfNotExists or DeployIfNotExists, isn't in the alias snapshot, so its fields can't be resolved. It is usually misspelled, or newer than the snapshot. With -AllowUnknownAlias it is a warning instead, and fields must then be written as full aliases.

To fix it: Check the type's spelling and case, refresh the snapshot with Update-BylawAliasCache, or use -AllowUnknownAlias.

See ADR-0008.

BYL2004

**Short field name under Resource *** (error)

Under Resource * there is no resource type to resolve a short name against, so a field must be a reserved field, such as location or tags, or a full alias.

To fix it: Write the full alias, or give the policy a resource type.

For example:

Resource * {
    Require 'An allowed location' {
        Field location | Must -BeIn (Param AllowedLocations)
    }
}

BYL2005

*Array field with [] outside Each (error)

Azure evaluates a condition on a field with [*] for every element of the array, so negating it doesn't give the opposite condition, and Bylaw couldn't invert it correctly in Require.

To fix it: Wrap it in Each, which says every element must meet the condition, or count the elements with Count -Where. For an array inside an array, nest one Each or Count per level.

For example:

Each networkAcls.ipRules[*] {
    Field value | Must -Not -Be '0.0.0.0/0'
}

See ADR-0032.

BYL2006

Unknown alias used because of -AllowUnknownAlias (warning)

The field isn't in the alias snapshot, but -AllowUnknownAlias is set, so Bylaw uses it as written. If the alias doesn't exist in Azure, the policy will never find a violation.

To fix it: Check the alias in Azure, for example with Get-AzPolicyAlias, then refresh the snapshot with Update-BylawAliasCache so the warning goes away.

See ADR-0008.

BYL2010

Alias snapshot can't be read (error)

The alias snapshot set with -AliasCachePath or aliasCache in bylaw.json wasn't found, isn't valid JSON, or isn't a Bylaw alias snapshot. The build stops, because no field could be checked.

To fix it: Check the path, which is relative to bylaw.json, or regenerate the file with Update-BylawAliasCache. Leave the setting out to use the bundled snapshot.

See ADR-0008.

BYL2020

Role map can't be read (error)

The role map set with -RoleCachePath or roleCache in bylaw.json wasn't found, isn't valid JSON, isn't a Bylaw role map, or has a role whose ID isn't a GUID. Modify and DeployIfNotExists need it to turn role names into IDs.

To fix it: Check the path, which is relative to bylaw.json, or regenerate the file with Update-BylawRoleCache. Leave the setting out to use the bundled role map.

See ADR-0022.