Skip to content

Commit

Permalink
Merge pull request #2 from takekazuomi/develop
Browse files Browse the repository at this point in the history
bicep 0.3.126
  • Loading branch information
takekazuomi authored Mar 22, 2021
2 parents 8718d04 + c7d0cd4 commit e605e58
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
IMAGE_NAME ?= takekazuomi/devcontainers-bicep
TAG ?= 0.3.1
BICEP_RELEASE = v0.3.1
TAG ?= 0.3.126
BICEP_RELEASE = v0.3.126

help: ## Show this help.
@sed -ne '/@sed/!s/## //p' $(MAKEFILE_LIST)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ This definition requires an Azure subscription to use. You can create a [free ac

## ChangeLog

- v0.3.126 Improvements to child resource declarations, Loop enhancements
- v0.3.1 bicep v0.3.1 loop support
- v0.0.9 bicep v0.2.212 conditional resources support
- v0.0.7 install GNU make
Expand Down
2 changes: 1 addition & 1 deletion src/loop-index.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var storageConfigurations = [
]

resource storageAccountResources 'Microsoft.Storage/storageAccounts@2019-06-01' = [for (config, i) in storageConfigurations: {
name: storageAccountNamePrefix + config.suffix + i
name: 'storageAccountNamePrefix${config.suffix}${i}'
location: resourceGroup().location
properties: {
supportsHttpsTrafficOnly: true
Expand Down
19 changes: 16 additions & 3 deletions src/nested-loops.bicep
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
resource parentResources 'Microsoft.Example/examples@2020-06-06' = [for parent in parents where parent.enabled: {
var parents = [
{
name: 'name'
enabled: true
children: [
{
name: 'name'
settingValue: 'value'
}
]
}
]

resource parentResources 'Microsoft.Example/examples@2020-06-06' = [for parent in parents: if (parent.enabled) {
name: parent.name
properties: {
children: [for child in parent.children where parent.includeChildren && child.enabled: {
children: [for child in parent.children: {
name: child.name
setting: child.settingValue
}]
}
}]
}]
11 changes: 11 additions & 0 deletions src/nsg-module.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
param name string

resource nsg 'Microsoft.Network/networkSecurityGroups@2020-06-01' = {
name: name
location: resourceGroup().location
}

output n object = {
name: nsg.name
id: nsg.id
}
20 changes: 20 additions & 0 deletions src/output-loop-module.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Output loops.
// Directly referencing a resource module or module collection is not currently supported in output loops. In order to loop outputs we need to apply an array indexer to the expression.

var nsgNames = [
'nsg1'
'nsg2'
'nsg3'
]

output nsgs array = [for i in range(0, length(nsgNames)): {
name: nsg[i].outputs.n.name
resourceId: nsg[i].outputs.n.id
}]

module nsg 'nsg-module.bicep' = [for name in nsgNames: {
name: name
params:{
name: name
}
}]
80 changes: 80 additions & 0 deletions src/output-loop-module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"functions": [],
"variables": {
"nsgNames": [
"nsg1",
"nsg2",
"nsg3"
]
},
"resources": [
{
"copy": {
"name": "nsg",
"count": "[length(variables('nsgNames'))]"
},
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-10-01",
"name": "[variables('nsgNames')[copyIndex()]]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"name": {
"value": "[variables('nsgNames')[copyIndex()]]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string"
}
},
"functions": [],
"resources": [
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-06-01",
"name": "[parameters('name')]",
"location": "[resourceGroup().location]"
}
],
"outputs": {
"n": {
"type": "object",
"value": {
"name": "[parameters('name')]",
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('name'))]"
}
}
}
}
}
}
],
"outputs": {
"nsgs": {
"type": "array",
"copy": {
"count": "[length(range(0, length(variables('nsgNames'))))]",
"input": {
"name": "[reference(resourceId('Microsoft.Resources/deployments', variables('nsgNames')[range(0, length(variables('nsgNames')))[copyIndex()]]), '2019-10-01').outputs.name]",
"resourceId": "[reference(resourceId('Microsoft.Resources/deployments', variables('nsgNames')[range(0, length(variables('nsgNames')))[copyIndex()]]), '2019-10-01').outputs.n.value]"
}
}
}
},
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.3.1.62928",
"templateHash": "11043703718792320070"
}
}
}
19 changes: 19 additions & 0 deletions src/output-loop.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Output loops.
// Directly referencing a resource module or module collection is not currently supported in output loops. In order to loop outputs we need to apply an array indexer to the expression.

var nsgNames = [
'nsg1'
'nsg2'
'nsg3'
]

resource nsg 'Microsoft.Network/networkSecurityGroups@2020-06-01' = [for name in nsgNames: {
name: name
location: resourceGroup().location
}]

output nsgs array = [for i in range(0, length(nsgNames)): {
name: nsg[i].name

resourceId: nsg[i].id
}]
18 changes: 18 additions & 0 deletions src/output-loop2.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Output loops.
// Directly referencing a resource module or module collection is not currently supported in output loops. In order to loop outputs we need to apply an array indexer to the expression.

var nsgNames = [
'nsg1'
'nsg2'
'nsg3'
]

resource nsg 'Microsoft.Network/networkSecurityGroups@2020-06-01' = [for name in nsgNames: {
name: name
location: resourceGroup().location
}]

output nsgs array = [for i in range(0, length(nsgNames)): {
name: nsg[i].name
resourceId: nsg[i].id
}]
11 changes: 11 additions & 0 deletions src/parent-child-resource.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource myParent 'My.Rp/parentType@2020-01-01' = {
name: 'myParent'
location: 'West US'
}

resource myChild 'My.Rp/parentType/childType@2020-01-01' = {
parent: myParent // pass parent reference
name: 'myChild' // don't require the full name to be formatted with '/' characters
}

output childProp string = myChild.properties.someProp
18 changes: 18 additions & 0 deletions src/resource-nesting.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// https://github.com/Azure/bicep/blob/main/docs/spec/resources.md#resource-nesting
resource myParent 'My.Rp/parentType@2020-01-01' = {
name: 'myParent'
location: 'West US'

// declares a resource of type 'My.Rp/parentType/childType@2020-01-01'
resource myChild 'childType' = {
name: 'myChild'
properties: {
displayName: 'child in ${parent.location}'
}
}
}

output childProp string = myParent::myChild.properties.displayName


// Error BCP082: The name "parent" does not exist in the current context. Did you mean "myParent"?
37 changes: 37 additions & 0 deletions src/resource-nesting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"functions": [],
"resources": [
{
"type": "My.Rp/parentType/childType",
"apiVersion": "2020-01-01",
"name": "[format('{0}/{1}', 'myParent', 'myChild')]",
"properties": {
"displayName": "[format('child in {0}', reference(resourceId('My.Rp/parentType', 'myParent'), '2020-01-01', 'full').location)]"
},
"dependsOn": [
"[resourceId('My.Rp/parentType', 'myParent')]"
]
},
{
"type": "My.Rp/parentType",
"apiVersion": "2020-01-01",
"name": "myParent",
"location": "West US"
}
],
"outputs": {
"childProp": {
"type": "string",
"value": "[reference(resourceId('My.Rp/parentType/childType', 'myParent', 'myChild')).displayName]"
}
},
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.3.126.58533",
"templateHash": "13471392052954043995"
}
}
}
21 changes: 21 additions & 0 deletions src/variable-loop.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var array1 = [
1
2
3
4
5
]

var array2 = [
1
2
3
4
5
]

var array3 = [for i in array1: {
i
}]

output r array = array3

0 comments on commit e605e58

Please sign in to comment.