Append is a block of Add operations, like Modify¶
Context and Problem Statement¶
append adds fields to a resource during a create or update request. Its details is an array of { field, value }. With a [*] alias the value is added to the array; with any other alias it sets the field, and the request is denied if it already has a different value. Learn recommends modify for tags, and Azure recommends modify over append in general, but append is still used: the Azure Landing Zones Library has five Append policies. How is it written?
Decision Drivers¶
- The same shape as
Modify: operations take their field from the pipeline. - Existing Append policies can be written in Bylaw without changing their behaviour.
Considered Options¶
- An
Appendblock ofAddoperations Append -Field ... -Value ...pairs as parameters- Not supporting
append, and pointing authors toModify
Decision Outcome¶
Chosen option: "An Append block of Add operations".
Append {
Field supportsHttpsTrafficOnly | Add $true
Field 'networkAcls.ipRules[*]' | Add @{ value = '40.40.40.40'; action = 'Allow' }
}
Addis the same keyword as inModify, and means "add this value". EachAddemits one{ "field": ..., "value": ... }, in the order written.AddOrReplaceandRemoveare compile errors insideAppend.- The field is a
Fieldor aTag. A[*]alias is allowed: Learn documents it as adding the value to the array, creating the array if it doesn't exist. So is a property of the elements,x[*].property, which Learn's array table documents as adding the value to that property of every element; until 2026-11-30 it was rejected. UnlikeModifyon array elements (ADR-0024), Learn doesn't mark it as in preview, so it has no warning. More than one[*], as inx[*].y[*], isn't documented and is an error. - The value can be a literal, including a hashtable for an object and an array, or a
Param,ArmorResourceGroupTag. - The same field in more than one
Addis a compile error. - Warning: a
Tagfield. Learn: "it's recommended to use the modify effect for tags instead." - Warning: a field that no
Requirechecks, as forModify(ADR-0024). Append marks existing resources that match the rule as non-compliant, so the rule should check what Append adds. - The effect is emitted as
Append.-Effect (Param Effect)may allowAppendandDisabled, the values the ALZ Append policies use. A literal effect gets a generated EPAC parameter with those values. Learn doesn't say whetherAuditorDenyare valid on a definition with append details, so they are compile errors until measured. Appendhas no roles: it changes the request, not the resource.- A hashtable value can't contain
ParamorArm(BYL1020), because Learn doesn't say whether expressions nested in an object value are evaluated. A parameter of typeObjectcan hold the whole value. - The details are emitted as an array, as Azure requires. The EPAC schema says
detailsis an object, so EPAC output gets the warning BYL4010 (ADR-0023). EPAC deploys it. The golden test checks the rest of the file against the schema.
Diagnostics¶
- Front end: BYL1036 (
AddOrReplaceorRemoveinAppend), BYL1037 (Add -ConditioninAppend), BYL1020 (ParamorArminside a hashtable value). As forModify, BYL1013 is an empty block, BYL1027 anAddwithout a value, BYL1030 a literal-Effect, and BYL1031 anAddwith no field. - Validation: BYL3080 (more than one
[*]in the path), BYL3081 (the same field twice), BYL3072 (an effect parameter that allows anything butAppendandDisabled), and the warnings BYL3082 (a tag field) and BYL3083 (a field noRequirechecks, where a[*]field counts as checked by anEachover it).
Consequences¶
- Good, because existing Append policies can move to Bylaw unchanged.
- Bad, because
Addmeans slightly different things inModify(set the field only if it has no value) and inAppend(add the value, and deny on conflict). The README describes each in its own section.
Confirmation¶
Unit tests cover each operation form, the errors and warnings, and the effect parameter. Golden tests cover a scalar field and a [*] field with an object value. Unit tests cover a [*].property field, in Append and in ConvertTo-Bylaw.
Pros and Cons of the Options¶
An Append block of Add operations¶
- Good, because it reads like
Modify. - Bad, because
Addis shared between two effects with slightly different behaviour.
Field and value parameters¶
- Good, because nothing is shared with
Modify. - Bad, because several fields need several pairs, which reads poorly.
Not supporting append¶
- Good, because there is less to build.
- Bad, because existing Append policies couldn't be written in Bylaw.
More Information¶
- Append effect
- Related: ADR-0024