You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/virtual-network-manager/how-to-exclude-elements.md
+89-53Lines changed: 89 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,67 +59,80 @@ List of supported operators:
59
59
60
60
## Basic editor
61
61
62
-
Assume you have the following virtual networks in your subscription. Each virtual network has either a *Production* or *Test* tag associated. You only want to select virtual networks with the Production tag and contain **VNet-A** in the name.
62
+
Assume you have the following virtual networks in your subscription. Each virtual network has an associated tag named **environment** with the respective value of *Production* or *Test*.
63
+
* myVNet01-EastUS - *Production*
64
+
* myVNet01-WestUS - *Production*
65
+
* myVNet02-WestUS - *Test*
66
+
* myVNet03-WestUS - *Test*
63
67
64
-
* VNet-A-EastUS - *Production*
65
-
* VNet-A-WestUS - *Production*
66
-
* VNet-B-WestUS - *Test*
67
-
* VNet-C-WestUS - *Test*
68
-
* VNetA - *Production*
69
-
* VNetB - *Test*
70
-
71
-
To begin using the basic editor to create your conditional statement, you need to create a new network group.
72
-
73
-
1. Go to your Azure Virtual Network Manager instance and select **Network Groups** under *Settings*. Then select **+ Create** to create a new network group.
68
+
You only want to select virtual networks that contain **VNet-A** in the name. To begin using the basic editor to create your conditional statement, you need to create a new network group.
74
69
70
+
1. Go to your Azure Virtual Network Manager instance and select **Network Groups** under **Settings**. Then select **+ Create** to create a new network group.
75
71
1. Enter a **Name** and an optional **Description** for the network group, and select **Add**.
76
72
1. Select the network group from the list and select **Create Azure Policy**.
77
73
1. Enter a **Policy name** and leave the **Scope** selections unless changes are needed.
78
-
1. Under **Criteria**, select **Tags** from the drop-down under *Parameter* and then select **Exist** from the drop-down under *Operator*.
79
-
80
-
1. Enter **Prod** under *Condition*, then select **Save**.
81
-
1. After a few minutes, select your network group and select **Group Members** under *Settings*. You should only see VNet-A-EastUS, VNet-A-WestUS, and VNetA show up in the list.
74
+
1. Under **Criteria**, select **Name** from the drop-down under **Parameter** and then select **Contains** from the drop-down under *Operator*.
75
+
1. Enter **WestUS** under **Condition**, then select **Save**.
76
+
1. After a few minutes, select your network group and select **Group Members** under **Settings**. You should only see myVNet01-WestUS, myVNet02-WestUS, and myVNet03-WestUS show up in the list.
82
77
83
-
> [!NOTE]
84
-
> The **basic editor** is only available during the creation of an Azure Policy.
78
+
> [!IMPORTANT]
79
+
> The **basic editor** is only available during the creation of an Azure Policy. Once a policy is created, all edits will be done using JSON in the **Policies** section of virtual network manager or via Azure Policy.
80
+
>
81
+
> When using the basic editor, your condition options will be limited through the portal experience. For complex conditions like creating a network group for VNets based on a customer-defined tag, you can used the advanced editor. Learn more about [Azure Policy definition structure](../governance/policy/concepts/definition-structure.md).
85
82
86
83
## Advanced editor
87
84
88
-
The advanced editor can be used to select virtual network during the creation of a network group or when updating an existing network group. Based in [JSON](../governance/policy/concepts/assignment-structure.md), the advanced editor is useful for creating and updating complex Azure Policy conditional statements by experienced users.
85
+
The advanced editor can be used to select virtual networks during the creation of a network group or when updating an existing network group. Based in [JSON](../governance/policy/concepts/assignment-structure.md), the advanced editor is useful for creating and updating complex Azure Policy conditional statements by experienced users.
86
+
87
+
### Create a new policy with advanced editor
88
+
89
+
1. Go to your Azure Virtual Network Manager instance and select **Network Groups** under **Settings**. Then select **+ Create** to create a new network group.
90
+
1. Enter a **Name** and an optional **Description** for the network group, and select **Add**.
91
+
1. Select the network group from the list and select **Create Azure Policy**.
92
+
1. Enter a **Policy name** and leave the **Scope** selections unless changes are needed.
93
+
1. Under **Criteria**, select **Advanced (JSON) editor** to open the editor.
94
+
1. Enter the following JSON code into the text box and select **Save**:
95
+
96
+
```json
97
+
{
98
+
"allOf": [
99
+
{
100
+
"field": "Name",
101
+
"contains": "myVNet01"
102
+
}
103
+
]
104
+
}
105
+
```
106
+
1. After a few minutes, select your network group and select **Group Members** under **Settings**. You should only see myVNet01-WestUS and myVNet01-EastUS.
89
107
90
-
1. Select the network group created in the previous section. Then select the **Conditional statements** tab.
108
+
### Edit an existing policy
91
109
92
-
1. You'll see the conditional statements for the network group in the advance editor view as followed:
110
+
1. Select the network group created in the previous section. Then select the **Policies** tab.
111
+
1. Select the policy created in the previous section.
112
+
1. You'll see the conditional statements for the network group in the advance editor view as follows:
93
113
94
114
```json
95
-
{
96
-
"allOf": [
97
-
{
98
-
"field": "tags['Environment']",
99
-
"exists": true
100
-
},
101
-
{
102
-
"field": "Name",
103
-
"contains": "VNet-A"
104
-
}
105
-
]
106
-
}
115
+
[
116
+
{
117
+
"allOf": [
118
+
{
119
+
"field": "Name",
120
+
"contains": "myVNet01"
121
+
}
122
+
]
123
+
}
124
+
]
107
125
```
108
126
109
-
The `"allOf"` parameter contains both the conditional statements that are separated by the **AND** logical operator.
110
-
111
-
1. To add another conditional statement for a *Name* field *not containing* **WestUS**, enter the following into the advanced editor:
127
+
1. To add another conditional statement for a **Name** field *not containing* **WestUS**, enter the following into the advanced editor:
112
128
113
129
```json
114
130
{
115
131
"allOf": [
116
-
{
117
-
"field": "tags['Environment']",
118
-
"exists": true
119
-
},
132
+
120
133
{
121
134
"field": "Name",
122
-
"contains": "VNet-A"
135
+
"contains": "VNet01"
123
136
},
124
137
{
125
138
"field": "Name",
@@ -129,14 +142,15 @@ The advanced editor can be used to select virtual network during the creation of
129
142
}
130
143
```
131
144
132
-
1. Then select **Evaluate**. You should only see VNet-A-EastUS virtual network in the list.
133
-
134
-
1. Select **Review + save** and then select **Save** once validation has passed.
135
-
136
-
See [Parameter and operators](#parameters) for the complete list of parameters and operators you can use with the advanced editor. See below for more examples:
145
+
The `"allOf"` parameter contains both the conditional statements that are separated by the **AND** logical operator.
146
+
1. Select Save.
147
+
1. After a few minutes, select your network group and select **Group Members** under **Settings**. You should only see myVNet01-EastUS.
137
148
149
+
See [Parameter and operators](#parameters) for the complete list of parameters and operators you can use with the advanced editor.
138
150
## More examples
139
151
152
+
Here are more examples of conditional statements in the advanced editor.
153
+
140
154
### Example 1: OR operator only
141
155
142
156
This example uses the **OR** logical operator to separate two conditional statements.
@@ -152,11 +166,11 @@ This example uses the **OR** logical operator to separate two conditional statem
152
166
"anyOf": [
153
167
{
154
168
"field": "Name",
155
-
"contains": "VNet-A"
169
+
"contains": "myVNet01"
156
170
},
157
171
{
158
172
"field": "Name",
159
-
"contains": "VNetA"
173
+
"contains": "myVNet02"
160
174
}
161
175
]
162
176
}
@@ -179,11 +193,11 @@ The `"anyOf"` parameter contains both the conditional statements that are separa
179
193
"anyOf": [
180
194
{
181
195
"field": "Name",
182
-
"contains": "VNet-A"
196
+
"contains": "myVNet01"
183
197
},
184
198
{
185
199
"field": "Name",
186
-
"contains": "VNetA"
200
+
"contains": "myVNet02"
187
201
}
188
202
]
189
203
},
@@ -194,12 +208,34 @@ The `"anyOf"` parameter contains both the conditional statements that are separa
194
208
]
195
209
}
196
210
```
197
-
198
211
Both `"allOf"` and `"anyOf"` are used in the code. Since the **AND** operator is last in the list, it is on the outer part of the code containing the two conditional statements with the **OR** operator.
199
212
200
-
> [!NOTE]
201
-
> Conditionals should filter on resource type Microsoft.Network/virtualNetwork to improve efficiency.
202
-
> This condition is prepended for you on any conditionals specified through the portal.
213
+
### Example 3: Using custom tag values with advanced editor
214
+
215
+
In this example, a conditional statement is created that finds virtual networks where the name includes **myVNet** AND the **environment** tag equals **production**.
216
+
217
+
* Advanced editor:
218
+
219
+
```json
220
+
221
+
{
222
+
"allOf": [
223
+
{
224
+
"field": "Name",
225
+
"contains": "myVNet"
226
+
},
227
+
{
228
+
"field": "tags['environment']",
229
+
"equals": "production"
230
+
}
231
+
]
232
+
}
233
+
234
+
```
235
+
236
+
> [!NOTE]
237
+
> Conditionals should filter on resource type Microsoft.Network/virtualNetwork to improve efficiency.
238
+
> This condition is prepended for you on any conditionals specified through the portal.
203
239
## Next steps
204
240
205
241
- Learn about [Network groups](concept-network-groups.md).
0 commit comments