1
1
---
2
2
title : Understand how effects work
3
3
description : Azure Policy definitions have various effects that determine how compliance is managed and reported.
4
- ms.date : 08/17 /2020
4
+ ms.date : 08/27 /2020
5
5
ms.topic : conceptual
6
6
---
7
7
# Understand Azure Policy effects
@@ -605,23 +605,51 @@ Example: Gatekeeper v2 admission control rule to allow only the specified contai
605
605
606
606
## Modify
607
607
608
- Modify is used to add, update, or remove tags on a resource during creation or update. A common
609
- example is updating tags on resources such as costCenter. A Modify policy should always have ` mode `
610
- set to _ Indexed_ unless the target resource is a resource group. Existing non-compliant resources
608
+ Modify is used to add, update, or remove properties or tags on a resource during creation or update.
609
+ A common example is updating tags on resources such as costCenter. Existing non-compliant resources
611
610
can be remediated with a [ remediation task] ( ../how-to/remediate-resources.md ) . A single Modify rule
612
611
can have any number of operations.
613
612
613
+ The following operations are supported by Modify:
614
+
615
+ - Add, replace or remove resource tags. For tags, a Modify policy should have ` mode ` set to
616
+ _ Indexed_ unless the target resource is a resource group.
617
+ - Add or replace the value of managed identity type (` identity.type ` ) of virtual machines and
618
+ virtual machine scale sets.
619
+ - Add or replace the values of certain aliases (preview).
620
+ - Use
621
+ ` Get-AzPolicyAlias | Select-Object -ExpandProperty 'Aliases' | Where-Object { $_.DefaultMetadata.Attributes -eq 'Modifiable' } `
622
+ in Azure PowerShell to get a list of aliases that can be used with Modify.
623
+
614
624
> [ !IMPORTANT]
615
- > Modify is currently only for use with tags. If you are managing tags, it's recommended to use
616
- > Modify instead of Append as Modify provides additional operation types and the ability to
617
- > remediate existing resources. However, Append is recommended if you aren't able to create a
618
- > managed identity .
625
+ > If you're managing tags, it's recommended to use Modify instead of Append as Modify provides
626
+ > additional operation types and the ability to remediate existing resources. However, Append is
627
+ > recommended if you aren't able to create a managed identity or Modify doesn't yet support the
628
+ > alias for the resource property .
619
629
620
630
### Modify evaluation
621
631
622
632
Modify evaluates before the request gets processed by a Resource Provider during the creation or
623
- updating of a resource. Modify adds or updates tags on a resource when the ** if** condition of the
624
- policy rule is met.
633
+ updating of a resource. The Modify operations are applied to the request content when the ** if**
634
+ condition of the policy rule is met. Each Modify operation can specify a condition that determines
635
+ when it's applied. Operations with conditions that are evaluated to _ false_ are skipped.
636
+
637
+ When an alias is specified, the following additional checks are performed to ensure that the Modify
638
+ operation doesn't change the request content in a way that causes the resource provider to reject
639
+ it:
640
+
641
+ - The property the alias maps to is marked as 'Modifiable' in the request's API version.
642
+ - The token type in the Modify operation matches the expected token type for the property in the
643
+ request's API version.
644
+
645
+ If either of these checks fail, the policy evaluation falls back to the specified
646
+ ** conflictEffect** .
647
+
648
+ > [ !IMPORTANT]
649
+ > It's recommeneded that Modify definitions that include aliases use the _ audit_ ** conflict effect**
650
+ > to avoid failing requests using API versions where the mapped property isn't 'Modifiable'. If the
651
+ > same alias behaves differently between API versions, conditional modify operations can be used to
652
+ > determine the modify operation used for each API version.
625
653
626
654
When a policy definition using the Modify effect is run as part of an evaluation cycle, it doesn't
627
655
make changes to resources that already exist. Instead, it marks any resource that meets the ** if**
@@ -636,11 +664,11 @@ needed for remediation and the **operations** used to add, update, or remove tag
636
664
- This property must include an array of strings that match role-based access control role ID
637
665
accessible by the subscription. For more information, see
638
666
[ remediation - configure policy definition] ( ../how-to/remediate-resources.md#configure-policy-definition ) .
639
- - The role defined must include all operations granted to the [ Contributor ] ( ../../../role-based-access-control/built-in-roles.md#contributor )
640
- role.
667
+ - The role defined must include all operations granted to the
668
+ [ Contributor ] ( ../../../role-based-access-control/built-in-roles.md#contributor ) role.
641
669
- ** conflictEffect** (optional)
642
670
- Determines which policy definition "wins" in the event that more than one policy definition
643
- modifies the same property.
671
+ modifies the same property or when the Modify operation doesn't work on the specified alias .
644
672
- For new or updated resources, the policy definition with _ deny_ takes precedence. Policy
645
673
definitions with _ audit_ skip all ** operations** . If more than one policy definition has
646
674
_ deny_ , the request is denied as a conflict. If all policy definitions have _ audit_ , then none
@@ -662,6 +690,12 @@ needed for remediation and the **operations** used to add, update, or remove tag
662
690
- ** value** (optional)
663
691
- The value to set the tag to.
664
692
- This property is required if ** operation** is _ addOrReplace_ or _ Add_ .
693
+ - ** condition** (optional)
694
+ - A string containing an Azure Policy language expression with
695
+ [ Policy functions] ( ./definition-structure.md#policy-functions ) that evaluates to _ true_ or
696
+ _ false_ .
697
+ - Doesn't support the following Policy functions: ` field() ` , ` resourceGroup() ` ,
698
+ ` subscription() ` .
665
699
666
700
### Modify operations
667
701
@@ -701,9 +735,9 @@ The **operation** property has the following options:
701
735
702
736
| Operation | Description |
703
737
| -| -|
704
- | addOrReplace | Adds the defined tag and value to the resource, even if the tag already exists with a different value. |
705
- | Add | Adds the defined tag and value to the resource. |
706
- | Remove | Removes the defined tag from the resource. |
738
+ | addOrReplace | Adds the defined property or tag and value to the resource, even if the property or tag already exists with a different value. |
739
+ | Add | Adds the defined property or tag and value to the resource. |
740
+ | Remove | Removes the defined property or tag from the resource. |
707
741
708
742
### Modify examples
709
743
@@ -753,6 +787,29 @@ with a parameterized value:
753
787
}
754
788
```
755
789
790
+ Example 3: Ensure that a storage account doesn't allow blob public access, the Modify operation
791
+ is applied only when evaluating requests with API version greater or equals to '2019-04-01':
792
+
793
+ ``` json
794
+ "then" : {
795
+ "effect" : " modify" ,
796
+ "details" : {
797
+ "roleDefinitionIds" : [
798
+ " /providers/microsoft.authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab"
799
+ ],
800
+ "conflictEffect" : " audit" ,
801
+ "operations" : [
802
+ {
803
+ "condition" : " [greaterOrEquals(requestContext().apiVersion, '2019-04-01')]" ,
804
+ "operation" : " addOrReplace" ,
805
+ "field" : " Microsoft.Storage/storageAccounts/allowBlobPublicAccess" ,
806
+ "value" : false
807
+ }
808
+ ]
809
+ }
810
+ }
811
+ ```
812
+
756
813
## Layering policy definitions
757
814
758
815
A resource may be impacted by several assignments. These assignments may be at the same scope or at
@@ -799,4 +856,4 @@ to validate the right policy assignments are affecting the right scopes.
799
856
- Understand how to [ programmatically create policies] ( ../how-to/programmatically-create.md ) .
800
857
- Learn how to [ get compliance data] ( ../how-to/get-compliance-data.md ) .
801
858
- Learn how to [ remediate non-compliant resources] ( ../how-to/remediate-resources.md ) .
802
- - Review what a management group is with [ Organize your resources with Azure management groups] ( ../../management-groups/overview.md ) .
859
+ - Review what a management group is with [ Organize your resources with Azure management groups] ( ../../management-groups/overview.md ) .
0 commit comments