Skip to content

Commit 895cac2

Browse files
Support target scopes for modules (#771)
* Add scope type * Very basic emitter, no validation * Attach function arguments to scope * Add ability to set target scope * Add example create-rg-lock-role-assignment * Fix up some tests * Pull in latest types, fix up tests * Check for multiple instances of targetScope declaration * Create INamedDeclarationSyntax * Tidy up * Add some tests * Update docs for scopes * Avoid outputting unrepresentible function types to JSON * Tidy up, add some comments * Combine AzResourceScope & ResoureScopeType enums * Fix vscode e2e test
1 parent 83b846d commit 895cac2

File tree

126 files changed

+10453
-4033
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+10453
-4033
lines changed

bicep-types-az

Submodule bicep-types-az updated 130 files

docs/examples/201/log-analytics-with-solutions-and-diagnostics/main.bicep

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,5 @@
11
param location string {
22
default: resourceGroup().location
3-
allowed: [
4-
'australiacentral'
5-
'australiaeast'
6-
'australiasoutheast'
7-
'brazilsouth'
8-
'canadacentral'
9-
'centralindia'
10-
'centralus'
11-
'eastasia'
12-
'eastus'
13-
'eastus2'
14-
'francecentral'
15-
'japaneast'
16-
'koreacentral'
17-
'northcentralus'
18-
'northeurope'
19-
'southafricanorth'
20-
'southcentralus'
21-
'southeastasia'
22-
'switzerlandnorth'
23-
'switzerlandwest'
24-
'uksouth'
25-
'ukwest'
26-
'westcentralus'
27-
'westeurope'
28-
'westus'
29-
'westus2'
30-
]
313
}
324

335
param logAnalyticsWorkspaceName string = 'la-${uniqueString(resourceGroup().id)}'

docs/examples/201/log-analytics-with-solutions-and-diagnostics/main.json

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,7 @@
44
"parameters": {
55
"location": {
66
"type": "string",
7-
"defaultValue": "[resourceGroup().location]",
8-
"allowedValues": [
9-
"australiacentral",
10-
"australiaeast",
11-
"australiasoutheast",
12-
"brazilsouth",
13-
"canadacentral",
14-
"centralindia",
15-
"centralus",
16-
"eastasia",
17-
"eastus",
18-
"eastus2",
19-
"francecentral",
20-
"japaneast",
21-
"koreacentral",
22-
"northcentralus",
23-
"northeurope",
24-
"southafricanorth",
25-
"southcentralus",
26-
"southeastasia",
27-
"switzerlandnorth",
28-
"switzerlandwest",
29-
"uksouth",
30-
"ukwest",
31-
"westcentralus",
32-
"westeurope",
33-
"westus",
34-
"westus2"
35-
]
7+
"defaultValue": "[resourceGroup().location]"
368
},
379
"logAnalyticsWorkspaceName": {
3810
"type": "string",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
targetScope = 'resourceGroup'
2+
3+
param principalId string
4+
param roleDefinitionId string
5+
param roleAssignmentName string
6+
7+
resource lockResource 'Microsoft.Authorization/locks@2016-09-01' = {
8+
name: 'DontDelete'
9+
properties: {
10+
level: 'CanNotDelete'
11+
notes: 'Prevent deletion of the resourceGroup'
12+
}
13+
}
14+
15+
resource assignmentResource 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
16+
name: guid(roleAssignmentName)
17+
properties: {
18+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleDefinitionId)
19+
principalId: principalId
20+
}
21+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"principalId": {
6+
"type": "string"
7+
},
8+
"roleDefinitionId": {
9+
"type": "string"
10+
},
11+
"roleAssignmentName": {
12+
"type": "string"
13+
}
14+
},
15+
"functions": [],
16+
"resources": [
17+
{
18+
"type": "Microsoft.Authorization/locks",
19+
"apiVersion": "2016-09-01",
20+
"name": "DontDelete",
21+
"properties": {
22+
"level": "CanNotDelete",
23+
"notes": "Prevent deletion of the resourceGroup"
24+
}
25+
},
26+
{
27+
"type": "Microsoft.Authorization/roleAssignments",
28+
"apiVersion": "2020-04-01-preview",
29+
"name": "[guid(parameters('roleAssignmentName'))]",
30+
"properties": {
31+
"roleDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', parameters('roleDefinitionId'))]",
32+
"principalId": "[parameters('principalId')]"
33+
}
34+
}
35+
]
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
targetScope = 'subscription'
2+
3+
param rgName string
4+
param rgLocation string
5+
param principalId string
6+
param roleDefinitionId string = 'b24988ac-6180-42a0-ab88-20f7382dd24c' // default is contributor
7+
param roleAssignmentName string = guid(principalId, roleDefinitionId, rgName)
8+
9+
resource newRg 'Microsoft.Resources/resourceGroups@2019-10-01' = {
10+
name: rgName
11+
location: rgLocation
12+
properties: {}
13+
}
14+
15+
module applyLock './applylock.bicep' = {
16+
name: 'applyLock'
17+
scope: resourceGroup(newRg.name)
18+
params: {
19+
principalId: principalId
20+
roleDefinitionId: roleDefinitionId
21+
roleAssignmentName: roleAssignmentName
22+
}
23+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"rgName": {
6+
"type": "string"
7+
},
8+
"rgLocation": {
9+
"type": "string"
10+
},
11+
"principalId": {
12+
"type": "string"
13+
},
14+
"roleDefinitionId": {
15+
"type": "string",
16+
"defaultValue": "b24988ac-6180-42a0-ab88-20f7382dd24c"
17+
},
18+
"roleAssignmentName": {
19+
"type": "string",
20+
"defaultValue": "[guid(parameters('principalId'), parameters('roleDefinitionId'), parameters('rgName'))]"
21+
}
22+
},
23+
"functions": [],
24+
"resources": [
25+
{
26+
"type": "Microsoft.Resources/resourceGroups",
27+
"apiVersion": "2019-10-01",
28+
"name": "[parameters('rgName')]",
29+
"location": "[parameters('rgLocation')]",
30+
"properties": {}
31+
},
32+
{
33+
"type": "Microsoft.Resources/deployments",
34+
"apiVersion": "2019-10-01",
35+
"name": "applyLock",
36+
"resourceGroup": "[parameters('rgName')]",
37+
"properties": {
38+
"expressionEvaluationOptions": {
39+
"scope": "inner"
40+
},
41+
"mode": "Incremental",
42+
"parameters": {
43+
"principalId": {
44+
"value": "[parameters('principalId')]"
45+
},
46+
"roleDefinitionId": {
47+
"value": "[parameters('roleDefinitionId')]"
48+
},
49+
"roleAssignmentName": {
50+
"value": "[parameters('roleAssignmentName')]"
51+
}
52+
},
53+
"template": {
54+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
55+
"contentVersion": "1.0.0.0",
56+
"parameters": {
57+
"principalId": {
58+
"type": "string"
59+
},
60+
"roleDefinitionId": {
61+
"type": "string"
62+
},
63+
"roleAssignmentName": {
64+
"type": "string"
65+
}
66+
},
67+
"functions": [],
68+
"resources": [
69+
{
70+
"type": "Microsoft.Authorization/locks",
71+
"apiVersion": "2016-09-01",
72+
"name": "DontDelete",
73+
"properties": {
74+
"level": "CanNotDelete",
75+
"notes": "Prevent deletion of the resourceGroup"
76+
}
77+
},
78+
{
79+
"type": "Microsoft.Authorization/roleAssignments",
80+
"apiVersion": "2020-04-01-preview",
81+
"name": "[guid(parameters('roleAssignmentName'))]",
82+
"properties": {
83+
"roleDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', parameters('roleDefinitionId'))]",
84+
"principalId": "[parameters('principalId')]"
85+
}
86+
}
87+
]
88+
}
89+
},
90+
"dependsOn": [
91+
"[resourceId('Microsoft.Resources/resourceGroups', parameters('rgName'))]"
92+
]
93+
}
94+
]
95+
}

docs/grammar.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ The following is the active pseudo-grammar of the bicep language.
33
```
44
program -> statement* EOF
55
statement ->
6+
targetScopeDecl |
67
parameterDecl |
78
variableDecl |
89
resourceDecl |
910
moduleDecl |
1011
outputDecl |
1112
NL
1213
14+
targetScopeDecl -> "targetScope" "=" expression
15+
1316
parameterDecl -> "parameter" IDENTIFIER(name) IDENTIFIER(type) (parameterDefaultValue | object(modifier))? NL
1417
parameterDefaultValue -> "=" expression
1518

docs/spec/modules.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,21 @@ output ipFqdn string = publicIp.outputs.ipFqdn
5454
```
5555

5656
### Notes
57-
* All paths in Bicep must be specified using the forward slash (`/`) directory separator to ensure consistent compilation cross-platform. The Windows backslash (`\`) character is unsupported.
57+
* All paths in Bicep must be specified using the forward slash (`/`) directory separator to ensure consistent compilation cross-platform. The Windows backslash (`\`) character is unsupported.
58+
59+
## Defining and configuring module scopes
60+
61+
It is possible to deploy across multiple scopes using the `scope` property when declaring a module. For example:
62+
63+
```bicep
64+
module publicIp './publicIpAddress.bicep' = {
65+
name: 'publicIp'
66+
scope: resourceGroup('someOtherRg') // pass in a scope to a different resourceGroup
67+
params: {
68+
publicIpResourceName: publicIpName
69+
dynamicAllocation: true
70+
}
71+
}
72+
```
73+
74+
Please see [Resource Scopes](./resource-scopes.md) for more information and advanced usage.

0 commit comments

Comments
 (0)