Modify is a block that replaces Effect, with operations that take their field from the pipeline¶
Context and Problem Statement¶
The modify effect changes resources when they are created or updated, and through remediation tasks for existing resources. Its then.details block has roleDefinitionIds, an optional conflictEffect, and a list of operations. Each operation has operation (addOrReplace, add or remove), field, value (required except for remove) and an optional condition. How do authors write this in Bylaw, and what does the compiler check?
Decision Drivers¶
- It should read like the rest of the DSL:
Musttakes its field from the pipeline. - The rule and the operations must agree. After remediation, a resource should be compliant. Otherwise it is remediated again on every evaluation and never becomes compliant.
- Mistakes that Azure only reports at deployment or remediation time should fail the build: a missing value,
removeon a non-tag field, a field that can't be modified.
Considered Options¶
- A
Modifyblock with pipeline operations:Tag Environment | AddOrReplace 'Production' - A
Modifyblock with named parameters:AddOrReplace -Field (Tag Environment) -Value 'Production' - Infer the operations from the
Requireblocks
Decision Outcome¶
Chosen option: "A Modify block with pipeline operations", because it matches Must and reads as a sentence.
Modify -Role 'Tag Contributor' {
Tag Environment | AddOrReplace 'Production'
Tag CostCenter | Add (ResourceGroupTag CostCenter)
Tag TempResource | Remove
}
The keyword¶
Modifytakes the place ofEffect. A policy has exactly one of them. Both, or neither, is a compile error.-Roleis required and takes one or more roles (ADR-0022).-ConflictEffectis optional and takesAudit,DenyorDisabled. It is emitted in lower case, as Learn documents it, and omitted when it isn't set (Azure's default isdeny).-Effect (Param Effect)makes the effect a parameter. Without it, the effect isModify.- The block holds one or more operations. An empty block is a compile error.
Operations¶
| DSL | Emitted operation |
Value |
|---|---|---|
... | AddOrReplace v |
addOrReplace |
required |
... | Add v |
add |
required |
... | Remove |
remove |
not allowed |
- The field comes from the pipeline:
Field nameorTag name.Elementis a compile error. - The value can be a literal,
Param,ArmorResourceGroupTag. -Condition (Arm '[...]')adds the operation'scondition.- Operations are emitted in the order written. Operation names are emitted as
addOrReplace,addandremove. Learn uses mixed casing in its examples, and Azure treats them the same.
Effect¶
- With a literal effect, EPAC output gets a generated effect parameter (ADR-0023), with allowed values
ModifyandDisabledand a default ofModify. These are the values built-in Modify policies use. - A declared effect parameter may allow
Modify,AuditandDisabled, and nothing else (BYL3062). Learn doesn't document whetherAuditis valid on a definition with amodifydetails block, so it was measured in the sandbox before being allowed (below). Denyin a Modify policy's effect parameter is a compile error (BYL3062).- Measured in the sandbox on 2026-11-26:
- Azure accepts a definition whose effect parameter allows
Modify,AuditandDisabled. - It refuses to assign it without a managed identity (
ResourceIdentityRequired), even with the effect set toAudit. So choosing Audit doesn't avoid the identity. - Assigned with a system-assigned identity and effect
Audit, it evaluates: the matching resource reported NonCompliant.
Validation¶
Errors found while the policy runs:
EffectandModifyin the same policy (BYL1026). A secondModifyisBYL1004, an empty or missing blockBYL1013.AddorAddOrReplacewithout a value, orRemovewith one (BYL1027).- A
-Conditionthat isn't anArmexpression (BYL1028). - A
-ConflictEffectother thanAudit,DenyorDisabled(BYL1029). - An
-Effectthat isn't a parameter or anArmexpression (BYL1030). - An operation with no field piped to it, or with
Elementor a value piped to it (BYL1031). - No
-Role(BYL1032).
Errors found when compiling:
- A role that isn't in the role map (
BYL3060), or the same role given twice in any form (BYL3061). Removeon a field that isn't a tag (BYL3063). Learn: "Only tags can be removed."- A field that isn't a tag, isn't
identity.typeand isn't marked Modifiable in the alias snapshot (BYL3064). Reserved fields such aslocationcan't be modified. identity.typeon a resource type other thanMicrosoft.Compute/virtualMachinesorMicrosoft.Compute/virtualMachineScaleSets(BYL3065). Learn says evaluation is skipped for other types, so the policy would silently do nothing. UnderResource *the type isn't known, so it isn't checked.- A field with more than one
[*](BYL3066). Learn's Modifying arrays documentsaddandaddOrReplaceon one array level, in preview:x[*]adds a member (addOrReplacefirst removes every existing member), andx[*].propertysets the property in every member. Until 2026-11-28 any[*]was rejected, in the belief that Learn didn't document it; it is allowed now, with a warning (BYL3075), andRemoveon it is stillBYL3063. - The same field in more than one operation (
BYL3067). - A
-Conditionthat usesfield(),resourceGroup()orsubscription()(BYL3068), which Learn says aren't supported there.
Warnings:
- An operation on a tag in a policy whose
Modeisn'tIndexed, unless the resource type isMicrosoft.Resources/subscriptions/resourceGroups(BYL3069). Learn: "For tags, a Modify policy should have mode set toindexedunless the target resource is a resource group." - An operation on a field that no
Requirechecks (BYL3070). The rule then doesn't depend on what the operation changes, so remediation can never make the resource compliant.Whenconditions don't count, because they decide where the policy applies, not whether a resource is compliant. -ConflictEffect Deny, or no conflict effect, on a policy that modifies an alias rather than a tag (BYL3071). Learn recommendsauditfor definitions that use aliases.- An operation on array elements,
x[*]orx[*].property(BYL3075), which Learn documents as in preview. ForAddOrReplaceonx[*]it also says that every existing member is removed first.
Consequences¶
- Good, because the rule and the fix sit side by side and are checked against each other.
- Good, because errors Azure only shows at remediation time fail the build.
- Bad, because authors write the requirement and the operation separately, for example
Must -Be 'Production'andAddOrReplace 'Production'. Inferring one from the other was rejected (below), and the warning catches the common mistake.
Confirmation¶
- Unit tests cover each operation, each option, every error and warning above, and the generated effect parameter.
- Golden tests cover tag inheritance in both forms (
addif missing,addOrReplaceto match), an alias operation with-ConflictEffectand-Condition, andRemove. - The sandbox script checks whether
Auditworks as an effect value on a Modify definition. It did on 2026-11-26.
Pros and Cons of the Options¶
Pipeline operations¶
- Good, because it is consistent with
Must. - Bad, because
Removetakes no argument, which looks slightly odd at the end of a pipeline.
Named parameters¶
- Good, because every part is labelled.
- Bad, because it is longer and unlike the rest of the DSL.
Inferring operations from Require¶
- Good, because nothing is written twice.
- Bad, because the mapping is ambiguous:
Must -Becould beaddoraddOrReplace, andMust -BeInhas no single value to set. It would also hide what the policy changes, which reviewers need to see.
More Information¶
- Modify effect
- Related: ADR-0017, ADR-0022, ADR-0023, ADR-0025