Skip to content

Commit 0e1c9ba

Browse files
Merge pull request #1475 from eladperets/master
Add new policy 'count' expressions
2 parents 904daf3 + 04bef46 commit 0e1c9ba

File tree

7 files changed

+104
-19
lines changed

7 files changed

+104
-19
lines changed

schemas/2015-10-01-preview/policyDefinition.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "https://schema.management.azure.com/schemas/2015-10-01-preview/policyDefinition.json#",
33
"$schema": "http://json-schema.org/draft-04/schema#",
44
"title": "Policy Definition",
5-
"description": "This schema defines Azure resource policy definition, please see https://azure.microsoft.com/en-us/documentation/articles/resource-manager-policy/ for more details.",
5+
"description": "This schema defines Azure Policy definition policy rules. For more details, see https://docs.microsoft.com/azure/governance/policy/.",
66
"type": "object",
77
"properties": {
88
"if": {

schemas/2016-12-01/policyDefinition.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "https://schema.management.azure.com/schemas/2016-12-01/policyDefinition.json#",
33
"$schema": "http://json-schema.org/draft-04/schema#",
44
"title": "Policy Definition",
5-
"description": "This schema defines Azure resource policy definition, please see https://azure.microsoft.com/en-us/documentation/articles/resource-manager-policy/ for more details.",
5+
"description": "This schema defines Azure Policy definition policy rules. For more details, see https://docs.microsoft.com/azure/governance/policy/.",
66
"type": "object",
77
"properties": {
88
"if": {

schemas/2018-05-01/policyDefinition.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "https://schema.management.azure.com/schemas/2018-05-01/policyDefinition.json#",
33
"$schema": "http://json-schema.org/draft-04/schema#",
44
"title": "Policy Definition",
5-
"description": "This schema defines Azure resource policy definition, please see https://azure.microsoft.com/en-us/documentation/articles/resource-manager-policy/ for more details.",
5+
"description": "This schema defines Azure Policy definition policy rules. For more details, see https://docs.microsoft.com/azure/governance/policy/.",
66
"type": "object",
77
"properties": {
88
"if": {

schemas/2019-01-01/policyDefinition.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "https://schema.management.azure.com/schemas/2019-01-01/policyDefinition.json#",
33
"$schema": "http://json-schema.org/draft-04/schema#",
44
"title": "Policy Definition",
5-
"description": "This schema defines Azure resource policy definition, please see https://azure.microsoft.com/documentation/articles/resource-manager-policy/ for more details.",
5+
"description": "This schema defines Azure Policy definition policy rules. For more details, see https://docs.microsoft.com/azure/governance/policy/.",
66
"type": "object",
77
"properties": {
88
"if": {

schemas/2019-06-01/policyDefinition.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "https://schema.management.azure.com/schemas/2019-06-01/policyDefinition.json#",
33
"$schema": "http://json-schema.org/draft-04/schema#",
44
"title": "Policy Definition",
5-
"description": "This schema defines Azure resource policy definition, please see https://azure.microsoft.com/documentation/articles/resource-manager-policy/ for more details.",
5+
"description": "This schema defines Azure Policy definition policy rules. For more details, see https://docs.microsoft.com/azure/governance/policy/.",
66
"type": "object",
77
"properties": {
88
"if": {

schemas/2019-09-01/policyDefinition.json

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -348,21 +348,45 @@
348348
]
349349
},
350350
"countExpression": {
351-
"properties": {
352-
"field": {
353-
"type": "string"
351+
"oneOf": [
352+
{
353+
"properties": {
354+
"field": {
355+
"type": "string"
356+
},
357+
"where": {
358+
"oneOf": [
359+
{ "$ref": "#/definitions/condition" },
360+
{ "$ref": "#/definitions/operatorNot" },
361+
{ "$ref": "#/definitions/operatorAnyOf" },
362+
{ "$ref": "#/definitions/operatorAllOf" }
363+
]
364+
}
365+
},
366+
"required": [ "field" ],
367+
"additionalProperties": false
354368
},
355-
"where": {
356-
"oneOf": [
357-
{ "$ref": "#/definitions/condition" },
358-
{ "$ref": "#/definitions/operatorNot" },
359-
{ "$ref": "#/definitions/operatorAnyOf" },
360-
{ "$ref": "#/definitions/operatorAllOf" }
361-
]
369+
{
370+
"properties": {
371+
"value": {
372+
"type": [ "array", "string" ]
373+
},
374+
"name": {
375+
"type": "string"
376+
},
377+
"where": {
378+
"oneOf": [
379+
{ "$ref": "#/definitions/condition" },
380+
{ "$ref": "#/definitions/operatorNot" },
381+
{ "$ref": "#/definitions/operatorAnyOf" },
382+
{ "$ref": "#/definitions/operatorAllOf" }
383+
]
384+
}
385+
},
386+
"required": [ "value" ],
387+
"additionalProperties": false
362388
}
363-
},
364-
"required": [ "field" ],
365-
"additionalProperties": false
389+
]
366390
},
367391
"operatorNot": {
368392
"properties": {

tests/2019-09-01/policyDefinition.tests.json

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
}
5858
},
5959
{
60-
"name": "PolicyDefinition tests - valid complex count condition",
60+
"name": "PolicyDefinition tests - valid complex field count condition",
6161
"definition": "https://schema.management.azure.com/schemas/2019-09-01/policyDefinition.json#",
6262
"json": {
6363
"if": {
@@ -93,6 +93,67 @@
9393
}
9494
}
9595
},
96+
{
97+
"name": "PolicyDefinition tests - valid value count conditions",
98+
"definition": "https://schema.management.azure.com/schemas/2019-09-01/policyDefinition.json#",
99+
"json": {
100+
"if": {
101+
"allOf": [
102+
{
103+
"count": {
104+
"value": []
105+
},
106+
"greater": 0
107+
},
108+
{
109+
"count": {
110+
"value": [],
111+
"name": "currentValue"
112+
},
113+
"greater": 0
114+
},
115+
{
116+
"count": {
117+
"value": [],
118+
"name": "currentValue",
119+
"where": {
120+
"value": "[current('currentValue')]",
121+
"equals": 1
122+
}
123+
},
124+
"greater": 0
125+
},
126+
{
127+
"count": {
128+
"value": "[parameters('arrayParam')]"
129+
},
130+
"greater": 0
131+
},
132+
{
133+
"count": {
134+
"value": "[parameters('arrayParam')]",
135+
"name": "currentValue"
136+
},
137+
"greater": 0
138+
},
139+
{
140+
"count": {
141+
"value": "[parameters('arrayParam')]",
142+
"name": "currentValue",
143+
"where": {
144+
"value": "[current('currentValue')]",
145+
"equals": 1
146+
}
147+
},
148+
"greater": 0
149+
}
150+
]
151+
},
152+
"then": {
153+
"effect": "deny"
154+
}
155+
}
156+
},
96157
{
97158
"name": "PolicyDefinition tests - valid append details",
98159
"definition": "https://schema.management.azure.com/schemas/2019-09-01/policyDefinition.json#",

0 commit comments

Comments
 (0)