При развертывании шаблона ниже в Azure я получаю следующую ошибку при попытке создать свой networkInterface:

{
  "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 ответ1

0

Кажется, что шаблон зависит от порядка, несмотря на наличие условий зависимости, которые развертывание не ожидает развертывания других ресурсов. Я переупорядочил ресурсы так, чтобы сетевые интерфейсы были последними, и теперь это работает.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .