updates
This commit is contained in:
Родитель
5932cd3526
Коммит
3dd4f0c8b4
|
@ -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 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
|
- Save your changes to the my-vm.json file
|
||||||
|
|
||||||
### Verify the Changes
|
### 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",
|
"type": "Microsoft.Resources/deployments",
|
||||||
"apiVersion": "2019-05-01",
|
"apiVersion": "2019-05-01",
|
||||||
"dependsOn": [
|
"dependsOn": [
|
||||||
"[variables('subnetId')]"
|
"[variables('virtualNetworkName')]"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"mode": "Incremental",
|
"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.
|
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.
|
||||||
|
|
||||||
|
## Add Copy Loop To Deploy Multiple VMs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 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
|
|
||||||
|
|
||||||
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.
|
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())]"
|
"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.
|
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,91 +29,25 @@
|
||||||
},
|
},
|
||||||
"resources": [
|
"resources": [
|
||||||
{
|
{
|
||||||
"type": "Microsoft.Network/virtualNetworks",
|
"name": "[concat('create-vm', copyIndex())]",
|
||||||
"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')]",
|
|
||||||
"dependsOn": [
|
|
||||||
"[variables('subnetId')]"
|
|
||||||
],
|
|
||||||
"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": "create-vm",
|
|
||||||
"type": "Microsoft.Resources/deployments",
|
"type": "Microsoft.Resources/deployments",
|
||||||
"apiVersion": "2019-05-01",
|
"apiVersion": "2019-05-01",
|
||||||
"dependsOn": [
|
"dependsOn": [
|
||||||
"[variables('subnetId')]"
|
"[variables('virtualNetworkName')]"
|
||||||
],
|
],
|
||||||
|
"copy": {
|
||||||
|
"name": "vmLoop",
|
||||||
|
"count": 3
|
||||||
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
"mode": "Incremental",
|
"mode": "Incremental",
|
||||||
"templateLink": {
|
"templateLink": {
|
||||||
"uri": "https://raw.githubusercontent.com/.../vm.json",
|
"uri": "https://raw.githubusercontent.com/Azure/Ignite2019_IaC_pre-day_docs/master/ARM%20Template/05%20-%20Reusability/vm.json",
|
||||||
"contentVersion": "1.0.0.0"
|
"contentVersion": "1.0.0.0"
|
||||||
},
|
},
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"vmName": {
|
"vmName": {
|
||||||
"value": "linux-vm"
|
"value": "[concat('vm-', copyIndex())]"
|
||||||
},
|
},
|
||||||
"adminUsername": {
|
"adminUsername": {
|
||||||
"value": "[parameters('adminUsername')]"
|
"value": "[parameters('adminUsername')]"
|
||||||
|
@ -129,6 +63,66 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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": "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Microsoft.Network/virtualNetworks",
|
||||||
|
"apiVersion": "2019-06-01",
|
||||||
|
"name": "virtualNetwork",
|
||||||
|
"location": "[parameters('location')]",
|
||||||
|
"dependsOn": [
|
||||||
|
"[variables('nsgName')]"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"addressSpace": {
|
||||||
|
"addressPrefixes": [
|
||||||
|
"10.0.0.0/16"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"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",
|
"type": "Microsoft.Network/networkInterfaces",
|
||||||
"apiVersion": "2019-06-01",
|
"apiVersion": "2019-06-01",
|
||||||
"name": "[variables('nicName')]",
|
"name": "[concat(parameters('vmName'), '-nic')]",
|
||||||
"location": "[parameters('location')]",
|
"location": "[parameters('location')]",
|
||||||
"properties": {
|
"properties": {
|
||||||
"ipConfigurations": [
|
"ipConfigurations": [
|
||||||
|
|
Загрузка…
Ссылка в новой задаче