Итак, я действительно новичок в шаблонах ARM, и для своего первого шаблона я пытаюсь создать шаблон, который задает несколько вопросов и, в конечном итоге, создает новый su bnet и NSG, если требуется, а затем виртуальную машину и все ее компоненты. .
Шаблон, который я вставил ниже, отлично работает, если я выберу «Да» для вопросов «Создать новый Су bnet» и «Создать новый NSG». Если я выбираю «Нет», я получаю сообщение об ошибке:
Ресурс шаблона 'dev-vnet /' для типа 'Microsoft. WindowsAzure .ResourceStack.Frontdoor.Common.Entities. TemplateGenericProperty`1 [System.String] 'в строке' 1 'и столбце' 306 'имеет неправильную длину сегмента. Вложенный тип ресурса должен иметь такое же количество сегментов, что и его имя ресурса. Тип ресурса root должен иметь длину сегмента на единицу больше, чем его имя ресурса.
Я понятия не имею, что это значит, и надеялся, что ответ «Нет» просто пропустит Su bnet и Создание NSG и продолжение, но это не так.
Может кто-нибудь помочь мне решить проблему, пожалуйста?
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"Create New Subnet": {
"type": "string",
"allowedValues": [
"Yes",
"No"
],
"defaultValue": "No",
"metadata": {
"description": ""
}
},
"New Subnet Name": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": ""
}
},
"New Subnet Prefix": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": ""
}
},
"Create New NSG": {
"type": "string",
"allowedValues": [
"Yes",
"No"
],
"defaultValue": "No",
"metadata": {
"description": "Select whether the VM should be in production or not."
}
},
"VM Name": {
"type": "string",
"metadata": {
"description": "The name of the VM you're creating. e.g. az-manage-01"
}
},
"VM Size": {
"type": "string",
"allowedValues": [
"Standard_D1_v2",
"Standard_D2s_v3"
],
"metadata": {
"description": "The compute specification required for the VM."
}
},
"Update Schedule": {
"type": "string",
"allowedValues": [
"Production",
"Testing"
],
"defaultValue": "Production",
"metadata": {
"description": "The update schedule that the VM will use."
}
},
"Subnet Name": {
"type": "string",
"metadata": {
"description": "The name of the subnet to deploy the VM into. e.g ActiveDirectory"
}
},
"IP Address": {
"type": "string",
"metadata": {
"description": "The IP address to assign to the VM. e.g. 10.0.1.5"
}
},
"Local Admin Password": {
"type": "securestring",
"metadata": {
"description": "Password used for local administrator account (contoso.admin) account on VM."
}
}
},
"variables": {
"VM Resource Group": "[resourceGroup().name]",
"Location": "[resourceGroup().location]",
"Operating System": "2019-Datacenter",
"Environment": "[subscription().displayName]",
"EnvironmentLower": "[toLower(variables('Environment'))]",
"Storage Account Name": "[concat('logs',variables('EnvironmentLower'))]",
"Storage Resource Group": "[concat('monitoring-',variables('EnvironmentLower'),'-rg')]",
"Image Publisher": "MicrosoftWindowsServer",
"Image Offer": "WindowsServer",
"Local Admin Username": "contoso.admin",
"vNET Resource Group": "[concat('network-',variables('EnvironmentLower'),'-rg')]",
"vNET Name": "[concat(variables('EnvironmentLower'),'-vnet')]",
"NIC Name": "[concat(parameters('VM Name'),'-nic')]",
"NSG Name": "[concat(parameters('New Subnet Name'),'-nsg')]",
"Subnet Prefix": "[concat(parameters('New Subnet Prefix'),'/24')]",
"Subnet ID": "[resourceId(variables('vNET Resource Group'), 'Microsoft.Network/virtualNetworks/subnets', variables('vNET Name'), parameters('Subnet Name'))]",
"Recovery Vault Resource Group": "[concat('recovery-',variables('EnvironmentLower'),'-rg')]",
"Recovery Vault Name": "[concat(variables('EnvironmentLower'),'-recovery-vault')]",
"Recovery Vault Backup Fabric": "Azure",
"Recovery Vault Backup Policy Name": "DefaultPolicy",
"Recovery Vault Protection Container": "[concat('iaasvmcontainer;iaasvmcontainerv2;', resourceGroup().name, ';', parameters('VM Name'))]",
"Recovery Vault Protected Item": "[concat('vm;iaasvmcontainerv2;', resourceGroup().name, ';', parameters('VM Name'))]"
},
"resources": [
{
"condition": "[equals(parameters('Create New NSG'), 'Yes')]",
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/networkSecurityGroups",
"name": "[variables('NSG Name')]",
"location": "[variables('location')]",
"properties": {
"securityRules": []
}
},
{
"apiVersion": "2017-05-10",
"name": "Nested_SubnetCreation",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[variables('vNET Resource Group')]",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"condition": "[equals(parameters('Create New Subnet'), 'Yes')]",
"apiVersion": "2018-04-01",
"type": "Microsoft.Network/virtualNetworks/subnets",
"name": "[concat(variables('vNET Name'), '/', parameters('New Subnet Name'))]",
"location": "[variables('location')]",
"properties": {
"addressPrefix": "[variables('Subnet Prefix')]",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('NSG Name'))]"
}
}
},
{
"apiVersion": "2017-05-10",
"name": "Nested_VMCreation",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[variables('VM Resource Group')]",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"apiVersion": "2019-09-01",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('NIC Name')]",
"location": "[variables('Location')]",
"dependsOn": [],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"privateIPAllocationMethod": "static",
"privateIPAddress": "[parameters('IP Address')]",
"subnet": {
"id": "[variables('Subnet ID')]"
}
}
}
]
}
},
{
"apiVersion": "2019-03-01",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('VM Name')]",
"location": "[variables('Location')]",
"tags": {
"Update Schedule": "[parameters('Update Schedule')]",
"Subscription": "[subscription().displayName]"
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces', variables('NIC Name'))]"
],
"properties": {
"licenseType": "Windows_Server",
"hardwareProfile": {
"vmSize": "[parameters('VM Size')]"
},
"osProfile": {
"computerName": "[parameters('VM Name')]",
"adminUsername": "[variables('Local Admin Username')]",
"adminPassword": "[parameters('Local Admin Password')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('Image Publisher')]",
"offer": "[variables('Image Offer')]",
"sku": "[variables('Operating System')]",
"version": "latest"
},
"osDisk": {
"name": "[concat(parameters('VM Name'),'-os')]",
"caching": "ReadWrite",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('NIC Name'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(resourceId(variables('Storage Resource Group'), 'Microsoft.Storage/storageAccounts', variables('Storage Account Name')), '2017-10-01').primaryEndpoints['blob']]"
}
}
}
},
{
"apiVersion": "2017-05-10",
"name": "Nested_AddVMToBackup",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[variables('Recovery Vault Resource Group')]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('VM Name'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"name": "[concat(variables('Recovery Vault Name'), '/', variables('Recovery Vault Backup Fabric'), '/', variables('Recovery Vault Protection Container'), '/', variables('Recovery Vault Protected Item'))]",
"apiVersion": "2016-06-01",
"location": "[resourceGroup().location]",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems",
"properties": {
"protectedItemType": "Microsoft.Compute/virtualMachines",
"policyId": "[resourceId('Microsoft.RecoveryServices/vaults/backupPolicies', variables('Recovery Vault Name'), variables('Recovery Vault Backup Policy Name'))]",
"sourceResourceId": "[resourceId(subscription().subscriptionId,variables('VM Resource Group'),'Microsoft.Compute/virtualMachines',parameters('VM Name'))]"
}
}
]
}
}
}
]
}
}
}
]
}
}
}
]
}