当我在 Azure 上部署下面的模板时,尝试创建网络接口时出现以下错误:
{
"error": {
"code": "InvalidResourceReference",
"message": "Resource /subscriptions/d897fa29-7454-411b-9709-d11a645bf42f/resourceGroups/TESTTEMPLATE001/providers/Microsoft.Network/networkSecurityGroups/NSGPSLSAX4PPVMOQP4 referenced by resource /subscriptions/d897fa29-7454-411b-9709-d11a645bf42f/resourceGroups/TESTTEMPLATE001/providers/Microsoft.Network/networkInterfaces/NIPSLSAX4PPVMOQP4 was not found. Please make sure that the referenced resource exists, and that both resources are in the same region.",
"details": [
{
"code": "NotFound",
"message": "Resource /subscriptions/d897fa29-7454-411b-9709-d11a645bf42f/resourceGroups/TESTTEMPLATE001/providers/Microsoft.Network/networkSecurityGroups/NSGPSLSAX4PPVMOQP4 not found."
}
]
}
}
模板:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"instance_name": {
"defaultValue": "ps",
"type": "String",
"maxLength": 8
},
"location": {
"defaultValue": "northeurope",
"type": "String"
}
},
"variables": {
"unique_string": "[uniqueString(resourceGroup().id, deployment().name)]",
"unique_name" : "[toUpper(concat(parameters('instance_name'), variables('unique_string')))]",
"networkSecurityGroupName": "[toUpper(concat('nsg',variables('unique_name')))]",
"virtualNetworkName" : "[toUpper(concat('ns', variables('unique_name')))]",
"addressPrefix": "10.0.0.0/16",
"subnetName": "Subnet",
"subnetPrefix": "10.0.0.0/24",
"subnetRef": "[toUpper(concat(variables('vnetID'),'/subnets/',variables('subnetName')))]",
"vnetID":"[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]",
"publicIPAddressName": "[toUpper(concat('ip', variables('unique_name')))]",
"storageAccountName": "[toLower(concat('sa', variables('unique_name')))]",
"networkInterfaceName": "[toUpper(concat('ni', variables('unique_name')))]"
},
"resources": [
{
"comments": "",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('unique_name')]",
"apiVersion": "2015-06-15",
"location": "[parameters('location')]",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_A1"
},
"storageProfile": {
"imageReference": {
"publisher": "Canonical",
"offer": "UbuntuServer",
"sku": "14.04.4-LTS",
"version": "latest"
},
"osDisk": {
"name": "[variables('unique_name')]",
"createOption": "FromImage",
"caching": "ReadWrite",
"vhd": {
"uri": "[concat('https', '://', 'sa', variables('unique_name'), '.blob.core.windows.net', '/vhds/', variables('unique_name'), 'osdisk','.vhd')]"
}
},
"dataDisks": []
},
"osProfile": {
"computerName": "[variables('unique_name')]",
"adminUsername": "spotscale",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{
"path": "/home/spotscale/.ssh/authorized_keys",
"keyData": "ssh-rsa <rsakey>"
}
]
}
},
"secrets": []
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
"[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
]
},
{
"apiVersion": "2016-03-30",
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [ "[variables('addressPrefix')]" ]
},
"subnets": [ {
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]"
}
} ]
}
},
{
"comments": "",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('networkInterfaceName')]",
"apiVersion": "2015-06-15",
"location": "[parameters('location')]",
"properties": {
"ipConfigurations": [
{
"name": "defaultipconfig",
"properties": {
"privateIPAddress": "10.5.0.4",
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[concat(resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName')), '/subnets/default')]"
}
}
}
],
"dnsSettings": {
"dnsServers": []
},
"enableIPForwarding": false,
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
},
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
]
}
},
{
"comments": "",
"type": "Microsoft.Network/networkSecurityGroups",
"name": "[variables('networkSecurityGroupName')]",
"apiVersion": "2015-06-15",
"location": "[parameters('location')]",
"properties": {
"securityRules": [
{
"name": "default-allow-ssh",
"properties": {
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "22",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 1000,
"direction": "Inbound"
}
},
{
"name": "allow-internet",
"properties": {
"protocol": "*",
"sourcePortRange": "*",
"destinationPortRange": "80",
"sourceAddressPrefix": "Internet",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 1010,
"direction": "Inbound"
}
}
]
},
"dependsOn": []
},
{
"comments": "",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"apiVersion": "2015-06-15",
"location": "[parameters('location')]",
"properties": {
"publicIPAllocationMethod": "Static",
"idleTimeoutInMinutes": 4
},
"dependsOn": []
},
{
"comments": "",
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "2015-06-15",
"location": "[parameters('location')]",
"tags": {},
"properties": {
"accountType": "Standard_LRS"
},
"dependsOn": []
}
]
}
我不明白为什么会发生这种情况。我尝试了很多方法,感觉就像在反复试验。有人能帮忙吗?谢谢。
答案1
模板似乎是顺序相关的,尽管有依赖子句,但部署不会等待其他资源部署。我已重新排序资源,以便网络接口位于最后,现在它可以正常工作了。