Как добавить существующую виртуальную сеть в базу данных Azure SQL с помощью шаблона Azure ARM?

В настоящее время я работаю над развертыванием базы данных SQL Azure в существующей виртуальной сети с использованием шаблонов Azure ARM.

azuredeploy.json

    {
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "sqlServerName": {
      "type": "string",
      "metadata": {
        "description": "The SQL Servername."
      }
    },
    "databaseName": {
      "type": "string",
      "metadata": {
        "description": "The SQL Database."
      }
    },
    "collation": {
      "type": "string",
      "metadata": {
        "description": "The Collation of SQL Database and SQL Server."
      }
    },
    "edition": {
      "type": "string",
      "metadata": {
        "description": "The edition of SQL Database."
      }
    },
    "maxSizeBytes": {
      "type": "string",
      "metadata": {
        "description": "The maxsize of SQL Database."
      }
    },
    "sqlAdministratorLogin": {
      "type": "string",
      "metadata": {
        "description": "The administrator username of the SQL Server."
      }
    },
    "sqlAdministratorLoginPassword": {
      "type": "securestring",
      "metadata": {
        "description": "The administrator password of the SQL Server."
      }
    },
    "transparentDataEncryption": {
      "type": "string",
      "allowedValues": [
        "Enabled",
        "Disabled"
      ],
      "defaultValue": "Enabled",
      "metadata": {
        "description": "Enable or disable Transparent Data Encryption (TDE) for the database."
      }
    },
    "zoneRedundant": {
      "type": "bool",
      "defaultValue": false
    },
    "startIpAddress": {
      "type": "string",
      "metadata": {
        "description": "The start IpAddress"
      }
    },
    "endIpAddress": {
      "type": "string",
      "metadata": {
        "description": "The end IpAddress."
      }
    },
    "sampleName": {
      "type": "string",
      "metadata": {
        "description": "The sampleName."
      }
    },
    "existingVnetName": {
      "type": "string",
      "metadata": {
        "description": "The name of the existing virtual netwok."
      }
    },
    "vnetRuleName": {
      "type": "string",
      "metadata": {
        "description": "The name of the virtual netwrok rule."
      }
    },
    "existingVirtualNetworkResourceGroup": {
      "type": "string",
      "metadata": {
        "description": "The name of the exisitng VNET resource group."
      }
    },
    "subscriptionID": {
      "type": "string",
      "metadata": {
        "description": "The ID of the exisitng azure subscription."
      }
    }
  },
  "variables": {
    "sqlServerName": "[parameters('sqlServerName')]",
    "databaseName": "[parameters('databaseName')]",
    "databaseEdition": "[parameters('edition')]",
    "databaseCollation": "[parameters('collation')]",
    "databaseServiceObjectiveName": "Basic",
    "vnetID": "[concat('/subscriptions/', parameters('subscriptionID'), '/resourceGroups/',parameters('existingVirtualNetworkResourceGroup'),'/','Microsoft.Network/virtualNetworks', parameters('existingVnetName'))]",
    //"vnetID": "[resourceId(parameters('resourceGroupName'), 'Microsoft.Network/virtualNetworks', parameters('existingVnetName'))]"
  },
  "resources": [
    {
      "name": "[variables('sqlServerName')]",
      "type": "Microsoft.Sql/servers",
      "apiVersion": "2014-04-01-preview",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "SqlServer"
      },
      "properties": {
        "administratorLogin": "[parameters('sqlAdministratorLogin')]",
        "administratorLoginPassword": "[parameters('sqlAdministratorLoginPassword')]",
        "version": "12.0"
      },
      "resources": [
        {
          "name": "[variables('databaseName')]",
          "type": "databases",
          "apiVersion": "2015-01-01",
          "location": "[resourceGroup().location]",
          "tags": {
            "displayName": "Database"
          },
          "properties": {
            "edition": "[variables('databaseEdition')]",
            "collation": "[variables('databaseCollation')]",
            "requestedServiceObjectiveName": "[variables('databaseServiceObjectiveName')]",
            "maxSizeBytes": "[parameters('maxSizeBytes')]",
            "sampleName": "[parameters('sampleName')]",
            "zoneRedundant": "[parameters('zoneRedundant')]"
          },
          "dependsOn": [
            "[variables('sqlServerName')]"
          ],
          "resources": [
            {
              "comments": "Transparent Data Encryption",
              "name": "current",
              "type": "transparentDataEncryption",
              "apiVersion": "2014-04-01-preview",
              "properties": {
                "status": "[parameters('transparentDataEncryption')]"
              },
              "dependsOn": [
                "[variables('databaseName')]"
              ]
            }
          ]
        },
        {
          "name": "AllowAllMicrosoftAzureIps",
          "type": "firewallrules",
          "apiVersion": "2014-04-01",
          "location": "[resourceGroup().location]",
          "properties": {
            "startIpAddress": "[parameters('startIpAddress')]",
            "endIpAddress": "[parameters('endIpAddress')]"
          },
          "dependsOn": [
            "[variables('sqlServerName')]"
          ]
        },
        {
          "comments": "Adding existing VNET to the SQL Server",
          "type": "Microsoft.Sql/servers/virtualNetworkRules",
          "name": "[concat(parameters('sqlServerName'), '/', parameters('vnetRuleName'))]",
          "apiVersion": "2015-05-01-preview",
          "scale": null,
          "properties": {
            "virtualNetworkSubnetId": "[variables('vnetID')]"
          },
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', parameters('sqlServerName'))]"
          ]
        }
      ]
    }
  ],
  "outputs": {
    "sqlServerFqdn": {
      "type": "string",
      "value": "[reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName]"
    },
    "databaseName": {
      "type": "string",
      "value": "[variables('databaseName')]"
    }
  }
}

Прежде чем я добавил этот раздел Microsoft.Sql/servers/virtualNetworkRules в файл azuredeploy.json, я смог создать новую базу данных SQL в azure.

    {
      "comments": "Adding existing VNET to the SQL Server",
      "type": "Microsoft.Sql/servers/virtualNetworkRules",
      "name": "[concat(parameters('sqlServerName'), '/', parameters('vnetRuleName'))]",
      "apiVersion": "2015-05-01-preview",
      "scale": null,
      "properties": {
        "virtualNetworkSubnetId": "[variables('vnetID')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Sql/servers', parameters('sqlServerName'))]"
      ]
    }

Но всякий раз, когда я добавлял этот раздел Microsoft.Sql/servers/virtualNetworkRules в файл azuredeploy.json, я не мог создать базу данных в существующей виртуальной сети, а также не дать никакого ответа.

Кто-нибудь может сказать мне, где я допустил ошибку в приведенном выше файле azuredeploy.json?


person Pradeep    schedule 20.03.2018    source источник


Ответы (1)


Наконец, я решил указанную выше проблему, заменив этот раздел кода на Microsoft.Sql/servers/virtualNetworkRules в следующих строках кода:

 {
      "comments": "Adding existing VNET to the SQL Server",
      "type": "Microsoft.Sql/servers/virtualNetworkRules",
      "name": "[concat(parameters('sqlServerName'), '/', parameters('vnetRuleName'))]",
      "apiVersion": "2015-05-01-preview",
      "scale": null,
      "properties": {
        "virtualNetworkSubnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('existingVnetName'), parameters('subnets_default_name'))]",
        "ignoreMissingVnetServiceEndpoint": "[parameters('ignoreMissingVnetServiceEndpoint')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Sql/servers', parameters('sqlServerName'))]"           
      ]
    }
person Pradeep    schedule 20.03.2018
comment
Также, если вы находитесь в другой группе ресурсов или подписке, не забудьте указать путь: docs.microsoft.com/en-us/azure/azure-resource-manager/ - person johnymachine; 29.04.2019