This commit is contained in:
Brian Moore 2019-10-30 12:03:33 -05:00
Родитель 5932cd3526
Коммит 3dd4f0c8b4
4 изменённых файлов: 80 добавлений и 224 удалений

Просмотреть файл

@ -55,6 +55,13 @@ Next, add some parameters to the my-vm.json template to make it more flexible fo
```
- Update the computerName property in the osProfile object to use the vmName parameter as well
- Update the name property on the networkInterce resource so that each VM will have a networkInterface with the same naming pattern as the VM itself
```json
"name": "[concat(parameters('vmName'), '-nic')]",
```
- Save your changes to the my-vm.json file
### Verify the Changes
@ -83,7 +90,7 @@ Next, add a deployment resource to the template. This resource will be used to
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-05-01",
"dependsOn": [
"[variables('subnetId')]"
"[variables('virtualNetworkName')]"
],
"properties": {
"mode": "Incremental",
@ -134,17 +141,7 @@ az group deployment create --resource-group IoC-02-000000 --template-file azured
After the deployment completes, or while the deployment is in process, you can open the Azure Portal and see the resources deployed into your resource group.
## Finish
This is the end of this section of the lab. To see a finished solution, see the final.json file in this folder.
But wait there's more! If you really want to see the power of what you created, continue on to the bonus section of this lab...
## Bonus - Add Copy Loop To Deploy Multiple VMs
## Add Copy Loop To Deploy Multiple VMs
Next, add a copy loop on the deployment resource that deploys the VM. This will allow the template to create multiple VMs in a single deployment without duplicating the code.
@ -169,8 +166,8 @@ Next, add a copy loop on the deployment resource that deploys the VM. This will
"value": "[concat('vm-', copyIndex())]"
```
This loop will create 3 VMs with the names vm-0, vm-1 and vm-2 in the resourceGroup.
This loop will create 3 VMs with the names vm-0, vm-1 and vm-2 in the resourceGroup. Deploy the template to see the results.
## Finish - Bonus
## Finish
This is the end of the bonus section of the lab. To see a finished solution, see the final.json file in this folder.

Просмотреть файл

@ -1,135 +0,0 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"nsgRules": {
"type": "array",
"defaultValue": [
22,
80,
443
]
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
},
"adminUsername": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
}
},
"variables": {
"nsgName": "nsg",
"virtualNetworkName": "virtualNetwork",
"subnet1Name": "subnet-1",
"subnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnet1Name'))]"
},
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2019-06-01",
"name": "virtualNetwork",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/16"
]
}
},
"resources": [
{
"type": "subnets",
"apiVersion": "2019-06-01",
"name": "subnet-1",
"dependsOn": [
"[variables('nsgName')]",
"virtualNetwork"
],
"properties": {
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"
},
"addressPrefix": "10.0.0.0/24"
}
},
{
"type": "subnets",
"apiVersion": "2019-06-01",
"name": "subnet-2",
"dependsOn": [
"virtualNetwork",
"subnet-1"
],
"properties": {
"addressPrefix": "10.0.1.0/24"
}
}
]
},
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2019-06-01",
"name": "[variables('nsgName')]",
"location": "[parameters('location')]",
"properties": {
"copy": {
"name": "securityRules",
"count": "[length(parameters('nsgRules'))]",
"input": {
"name": "[concat('allow-', parameters('nsgRules')[copyIndex('securityRules')])]",
"properties": {
"priority": "[add(1000, copyIndex('securityRules'))]",
"sourceAddressPrefix": "*",
"protocol": "Tcp",
"destinationPortRange": "[parameters('nsgRules')[copyIndex('securityRules')]]",
"access": "Allow",
"direction": "Inbound",
"sourcePortRange": "*",
"destinationAddressPrefix": "*"
}
}
}
}
},
{
"name": "[concat('create-vm', copyIndex())]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-05-01",
"dependsOn": [
"[variables('subnetId')]"
],
"copy": {
"name": "vmLoop",
"count": 3
},
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "https://raw.githubusercontent.com/.../vm.json",
"contentVersion": "1.0.0.0"
},
"parameters": {
"vmName": {
"value": "[concat('vm-', copyIndex())]"
},
"adminUsername": {
"value": "[parameters('adminUsername')]"
},
"adminPassword": {
"value": "[parameters('adminPassword')]"
},
"location": {
"value": "[parameters('location')]"
},
"subnetId": {
"value": "[variables('subnetId')]"
}
}
}
}
]
}

Просмотреть файл

@ -29,57 +29,49 @@
},
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2019-06-01",
"name": "virtualNetwork",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/16"
]
}
},
"resources": [
{
"type": "subnets",
"apiVersion": "2019-06-01",
"name": "subnet-1",
"name": "[concat('create-vm', copyIndex())]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-05-01",
"dependsOn": [
"[variables('nsgName')]",
"virtualNetwork"
"[variables('virtualNetworkName')]"
],
"properties": {
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"
"copy": {
"name": "vmLoop",
"count": 3
},
"addressPrefix": "10.0.0.0/24"
}
},
{
"type": "subnets",
"apiVersion": "2019-06-01",
"name": "subnet-2",
"dependsOn": [
"virtualNetwork",
"subnet-1"
],
"properties": {
"addressPrefix": "10.0.1.0/24"
"mode": "Incremental",
"templateLink": {
"uri": "https://raw.githubusercontent.com/Azure/Ignite2019_IaC_pre-day_docs/master/ARM%20Template/05%20-%20Reusability/vm.json",
"contentVersion": "1.0.0.0"
},
"parameters": {
"vmName": {
"value": "[concat('vm-', copyIndex())]"
},
"adminUsername": {
"value": "[parameters('adminUsername')]"
},
"adminPassword": {
"value": "[parameters('adminPassword')]"
},
"location": {
"value": "[parameters('location')]"
},
"subnetId": {
"value": "[variables('subnetId')]"
}
}
}
]
},
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2019-06-01",
"name": "[variables('nsgName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[variables('subnetId')]"
],
"properties": {
"copy": {
"copy": [
{
"name": "securityRules",
"count": "[length(parameters('nsgRules'))]",
"input": {
@ -96,38 +88,40 @@
}
}
}
]
}
},
{
"name": "create-vm",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-05-01",
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2019-06-01",
"name": "virtualNetwork",
"location": "[parameters('location')]",
"dependsOn": [
"[variables('subnetId')]"
"[variables('nsgName')]"
],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "https://raw.githubusercontent.com/.../vm.json",
"contentVersion": "1.0.0.0"
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/16"
]
},
"parameters": {
"vmName": {
"value": "linux-vm"
},
"adminUsername": {
"value": "[parameters('adminUsername')]"
},
"adminPassword": {
"value": "[parameters('adminPassword')]"
},
"location": {
"value": "[parameters('location')]"
},
"subnetId": {
"value": "[variables('subnetId')]"
}
"subnets": [
{
"name": "subnet-2",
"properties": {
"addressPrefix": "10.0.1.0/24"
}
},
{
"name": "subnet-1",
"properties": {
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"
},
"addressPrefix": "10.0.0.0/24"
}
}
]
}
}
]

Просмотреть файл

@ -26,7 +26,7 @@
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2019-06-01",
"name": "[variables('nicName')]",
"name": "[concat(parameters('vmName'), '-nic')]",
"location": "[parameters('location')]",
"properties": {
"ipConfigurations": [