Initiatives¶
An initiative groups policies so they're assigned together, and passes its own parameters to theirs. It sits beside policies, in the same or other files, and includes them by name. Built-in policies are included by ID.
Initiative 'tagging-baseline' {
Properties @{
DisplayName = 'Tagging baseline'
Category = 'Tags'
Version = '1.0.0'
}
Parameter RequiredTag @{ Default = 'CostCenter' }
PolicyDefinition 'general-require-tag' -Parameters @{
tagName = Param RequiredTag
}
# The same policy twice, with a reference ID for each.
PolicyDefinition 'tags-inherit-from-resource-group' -ReferenceId 'inherit-cost-center' -Parameters @{ tagName = 'CostCenter' }
PolicyDefinition 'tags-inherit-from-resource-group' -ReferenceId 'inherit-owner' -Parameters @{ tagName = 'Owner' }
# A built-in policy, by its GUID.
PolicyDefinition -Id 96670d01-0a4d-4649-9c89-2d3abc0a5025 -ReferenceId 'require-environment' -Parameters @{
tagName = 'Environment'
}
}
PolicyDefinitiontakes-ReferenceId(the member'spolicyDefinitionReferenceId, defaulting to the policy name and required with-Id),-Parameters,-Version(adefinitionVersionsuch as1.*.*) and-Group. Values passed are literals,Param(an initiative parameter),ArmorResourceGroupTag.DefinitionGroup 'name'declares a group, with-DisplayName,-Category,-Descriptionand-AdditionalMetadataId. Members join it with-Group. EPAC's schema only allows a group's name and-AdditionalMetadataId, so the other options are an EPAC error.- Checked when the build runs: once every file has compiled, each member from the build is checked against the policy it names. The policy must exist, every value must go to one of its parameters, every parameter without a default must be given one, and values must fit the parameter's type and allowed values. An initiative parameter passed to a policy can't allow values the policy doesn't. The checks use the parameters each format emits, so in EPAC output you can pass
effectto a policy with a literal effect, whose generated parameter has a default. -Idtakes a definition ID, or a built-in policy's GUID on its own, which is short for/providers/Microsoft.Authorization/policyDefinitions/<guid>. When a member's arguments make a long line, splat them from a hashtable, without backticks:
$requireEnvironment = @{
Id = '96670d01-0a4d-4649-9c89-2d3abc0a5025'
ReferenceId = 'require-environment'
Version = '1.*.*'
Parameters = @{ tagName = 'Environment' }
}
PolicyDefinition @requireEnvironment
- Not checked: members by
-Id. Bylaw has no copy of the built-in definitions, so only the shape of the ID is checked. -Versionon a member from the build must match the policy'sPolicyVersionif it has one, which is the top-levelversionAzure matches it against. Otherwise it must match the policy'sVersion, and the build warns that the pin may not select the version you expect, since the policy has no top-levelversion.- Output: EPAC initiatives reference members from the build by
policyDefinitionName, as EPAC requires, and anything else bypolicyDefinitionId. Plain JSON needs a full ID for every member, so set the scope the build's policies are deployed at with-DefinitionScopeordefinitionScopeinbylaw.json. Initiatives are written to-InitiativeOutputPath, which defaults to-OutputPath. For EPAC, use its two folders:
Build-Bylaw ./policies -OutputPath ./Definitions/policyDefinitions -InitiativeOutputPath ./Definitions/policySetDefinitions