クイック スタート: ARM テンプレートを使用して SQL Server VM を作成する

この Azure Resource Manager テンプレート (ARM テンプレート) を使用して、AZURE 仮想マシン (VM) に SQL Server をデプロイします。

ARM テンプレートは、プロジェクトのインフラストラクチャと構成を定義する JavaScript Object Notation (JSON) ファイルです。 このテンプレートでは、宣言型の構文が使用されています。 宣言型の構文では、デプロイしようとしているものを、デプロイを作成する一連のプログラミング コマンドを記述しなくても記述できます。

環境が前提条件を満たしていて、ARM テンプレートの使用に慣れている場合は、 [Azure へのデプロイ] ボタンを選択します。 Azure portal でテンプレートが開きます。

Azure に展開する

[前提条件]

SQL Server VM ARM テンプレートには、次のものが必要です。

テンプレートを確認する

このクイックスタートで使用されるテンプレートは Azure クイックスタート テンプレートからのものです。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.39.26.7824",
      "templateHash": "8885750212402280260"
    }
  },
  "parameters": {
    "virtualMachineName": {
      "type": "string",
      "defaultValue": "myVM",
      "metadata": {
        "description": "The name of the VM"
      }
    },
    "virtualMachineSize": {
      "type": "string",
      "defaultValue": "Standard_D8s_v3",
      "metadata": {
        "description": "The virtual machine size."
      }
    },
    "existingVirtualNetworkName": {
      "type": "string",
      "metadata": {
        "description": "Specify the name of an existing VNet in the same resource group"
      }
    },
    "existingVnetResourceGroup": {
      "type": "string",
      "defaultValue": "[resourceGroup().name]",
      "metadata": {
        "description": "Specify the resrouce group of the existing VNet"
      }
    },
    "existingSubnetName": {
      "type": "string",
      "metadata": {
        "description": "Specify the name of the Subnet Name"
      }
    },
    "imageOffer": {
      "type": "string",
      "defaultValue": "sql2019-ws2022",
      "allowedValues": [
        "sql2025-ws2025",
        "sql2022-ws2022",
        "sql2019-ws2019",
        "sql2017-ws2019",
        "sql2019-ws2022",
        "SQL2016SP1-WS2016",
        "SQL2016SP2-WS2016",
        "SQL2014SP3-WS2012R2",
        "SQL2014SP2-WS2012R2"
      ],
      "metadata": {
        "description": "Windows Server and SQL Offer"
      }
    },
    "sqlSku": {
      "type": "string",
      "defaultValue": "standard-gen2",
      "allowedValues": [
        "standard-gen2",
        "enterprise-gen2",
        "SQLDEV-gen2",
        "web-gen2",
        "enterprisedbengineonly-gen2"
      ],
      "metadata": {
        "description": "SQL Server Sku"
      }
    },
    "adminUsername": {
      "type": "string",
      "metadata": {
        "description": "The admin user name of the VM"
      }
    },
    "adminPassword": {
      "type": "securestring",
      "metadata": {
        "description": "The admin password of the VM"
      }
    },
    "storageWorkloadType": {
      "type": "string",
      "defaultValue": "General",
      "allowedValues": [
        "General",
        "OLTP",
        "DW"
      ],
      "metadata": {
        "description": "SQL Server Workload Type"
      }
    },
    "sqlDataDisksCount": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "maxValue": 8,
      "metadata": {
        "description": "Amount of data disks (1TB each) for SQL Data files"
      }
    },
    "dataPath": {
      "type": "string",
      "defaultValue": "F:\\SQLData",
      "metadata": {
        "description": "Path for SQL Data files. Please choose drive letter from F to Z, and other drives from A to E are reserved for system"
      }
    },
    "sqlLogDisksCount": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "maxValue": 8,
      "metadata": {
        "description": "Amount of data disks (1TB each) for SQL Log files"
      }
    },
    "logPath": {
      "type": "string",
      "defaultValue": "G:\\SQLLog",
      "metadata": {
        "description": "Path for SQL Log files. Please choose drive letter from F to Z and different than the one used for SQL data. Drive letter from A to E are reserved for system"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "securityType": {
      "type": "string",
      "defaultValue": "TrustedLaunch",
      "allowedValues": [
        "Standard",
        "TrustedLaunch"
      ],
      "metadata": {
        "description": "Security Type of the Virtual Machine."
      }
    }
  },
  "variables": {
    "securityProfileJson": {
      "uefiSettings": {
        "secureBootEnabled": true,
        "vTpmEnabled": true
      },
      "securityType": "[parameters('securityType')]"
    },
    "networkInterfaceName": "[format('{0}-nic', parameters('virtualMachineName'))]",
    "networkSecurityGroupName": "[format('{0}-nsg', parameters('virtualMachineName'))]",
    "networkSecurityGroupRules": [
      {
        "name": "RDP",
        "properties": {
          "priority": 300,
          "protocol": "Tcp",
          "access": "Allow",
          "direction": "Inbound",
          "sourceAddressPrefix": "*",
          "sourcePortRange": "*",
          "destinationAddressPrefix": "*",
          "destinationPortRange": "3389"
        }
      }
    ],
    "publicIpAddressName": "[format('{0}-publicip-{1}', parameters('virtualMachineName'), uniqueString(parameters('virtualMachineName')))]",
    "publicIpAddressType": "Static",
    "publicIpAddressSku": "Standard",
    "diskConfigurationType": "NEW",
    "nsgId": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]",
    "subnetRef": "[resourceId(parameters('existingVnetResourceGroup'), 'Microsoft.Network/virtualNetWorks/subnets', parameters('existingVirtualNetworkName'), parameters('existingSubnetName'))]",
    "dataDisksLuns": "[range(0, parameters('sqlDataDisksCount'))]",
    "logDisksLuns": "[range(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount'))]",
    "dataDisks": {
      "createOption": "Empty",
      "caching": "ReadOnly",
      "writeAcceleratorEnabled": false,
      "storageAccountType": "Premium_LRS",
      "diskSizeGB": 1023
    },
    "tempDbPath": "D:\\SQLTemp",
    "extensionName": "GuestAttestation",
    "extensionPublisher": "Microsoft.Azure.Security.WindowsAttestation",
    "extensionVersion": "1.0",
    "maaTenantName": "GuestAttestation"
  },
  "resources": [
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2022-01-01",
      "name": "[variables('publicIpAddressName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[variables('publicIpAddressSku')]"
      },
      "properties": {
        "publicIPAllocationMethod": "[variables('publicIpAddressType')]"
      }
    },
    {
      "type": "Microsoft.Network/networkSecurityGroups",
      "apiVersion": "2022-01-01",
      "name": "[variables('networkSecurityGroupName')]",
      "location": "[parameters('location')]",
      "properties": {
        "securityRules": "[variables('networkSecurityGroupRules')]"
      }
    },
    {
      "type": "Microsoft.Network/networkInterfaces",
      "apiVersion": "2022-01-01",
      "name": "[variables('networkInterfaceName')]",
      "location": "[parameters('location')]",
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "subnet": {
                "id": "[variables('subnetRef')]"
              },
              "privateIPAllocationMethod": "Dynamic",
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIpAddressName'))]"
              }
            }
          }
        ],
        "enableAcceleratedNetworking": true,
        "networkSecurityGroup": {
          "id": "[variables('nsgId')]"
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]",
        "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIpAddressName'))]"
      ]
    },
    {
      "type": "Microsoft.Compute/virtualMachines",
      "apiVersion": "2022-03-01",
      "name": "[parameters('virtualMachineName')]",
      "location": "[parameters('location')]",
      "properties": {
        "hardwareProfile": {
          "vmSize": "[parameters('virtualMachineSize')]"
        },
        "storageProfile": {
          "copy": [
            {
              "name": "dataDisks",
              "count": "[length(range(0, length(range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount'))))))]",
              "input": {
                "lun": "[range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))[range(0, length(range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))))[copyIndex('dataDisks')]]]",
                "createOption": "[variables('dataDisks').createOption]",
                "caching": "[if(greaterOrEquals(range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))[range(0, length(range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))))[copyIndex('dataDisks')]], parameters('sqlDataDisksCount')), 'None', variables('dataDisks').caching)]",
                "writeAcceleratorEnabled": "[variables('dataDisks').writeAcceleratorEnabled]",
                "diskSizeGB": "[variables('dataDisks').diskSizeGB]",
                "managedDisk": {
                  "storageAccountType": "[variables('dataDisks').storageAccountType]"
                }
              }
            }
          ],
          "osDisk": {
            "createOption": "FromImage",
            "managedDisk": {
              "storageAccountType": "Premium_LRS"
            }
          },
          "imageReference": {
            "publisher": "MicrosoftSQLServer",
            "offer": "[parameters('imageOffer')]",
            "sku": "[parameters('sqlSku')]",
            "version": "latest"
          }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
            }
          ]
        },
        "osProfile": {
          "computerName": "[parameters('virtualMachineName')]",
          "adminUsername": "[parameters('adminUsername')]",
          "adminPassword": "[parameters('adminPassword')]",
          "windowsConfiguration": {
            "enableAutomaticUpdates": true,
            "provisionVMAgent": true
          }
        },
        "securityProfile": "[if(equals(parameters('securityType'), 'TrustedLaunch'), variables('securityProfileJson'), null())]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
      ]
    },
    {
      "condition": "[and(equals(parameters('securityType'), 'TrustedLaunch'), and(equals(variables('securityProfileJson').uefiSettings.secureBootEnabled, true()), equals(variables('securityProfileJson').uefiSettings.vTpmEnabled, true())))]",
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "apiVersion": "2022-03-01",
      "name": "[format('{0}/{1}', parameters('virtualMachineName'), variables('extensionName'))]",
      "location": "[parameters('location')]",
      "properties": {
        "publisher": "[variables('extensionPublisher')]",
        "type": "[variables('extensionName')]",
        "typeHandlerVersion": "[variables('extensionVersion')]",
        "autoUpgradeMinorVersion": true,
        "enableAutomaticUpgrade": true,
        "settings": {
          "AttestationConfig": {
            "MaaSettings": {
              "maaEndpoint": "",
              "maaTenantName": "[variables('maaTenantName')]"
            },
            "AscSettings": {
              "ascReportingEndpoint": "",
              "ascReportingFrequency": ""
            },
            "useCustomToken": "false",
            "disableAlerts": "false"
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]"
      ]
    },
    {
      "type": "Microsoft.SqlVirtualMachine/sqlVirtualMachines",
      "apiVersion": "2022-07-01-preview",
      "name": "[parameters('virtualMachineName')]",
      "location": "[parameters('location')]",
      "properties": {
        "virtualMachineResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
        "sqlManagement": "Full",
        "sqlServerLicenseType": "PAYG",
        "storageConfigurationSettings": {
          "diskConfigurationType": "[variables('diskConfigurationType')]",
          "storageWorkloadType": "[parameters('storageWorkloadType')]",
          "sqlDataSettings": {
            "luns": "[variables('dataDisksLuns')]",
            "defaultFilePath": "[parameters('dataPath')]"
          },
          "sqlLogSettings": {
            "luns": "[variables('logDisksLuns')]",
            "defaultFilePath": "[parameters('logPath')]"
          },
          "sqlTempDbSettings": {
            "defaultFilePath": "[variables('tempDbPath')]"
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]"
      ]
    }
  ],
  "outputs": {
    "adminUsername": {
      "type": "string",
      "value": "[parameters('adminUsername')]"
    }
  }
}

テンプレートには、次の 5 つの Azure リソースが定義されています。

Azure VM 上のその他の SQL Server テンプレートについては、 クイック スタート テンプレート ギャラリーを参照してください。

テンプレートをデプロイする

  1. Azure にサインインし、テンプレートを開くには次のイメージを選択します。 テンプレートは、目的の SQL Server バージョンがインストールされた仮想マシンを作成し、VM を SQL IaaS Agent 拡張機能に登録します。

    Azure に展開する

  2. 配置フォームのフィールドを次の順序で入力します。

    • サブスクリプション – Azure サブスクリプションを選択します。
    • リソース グループ – SQL Server VM 用に準備されたリソース グループを選択します。
    • リージョン – リージョン (米国中部など) を選択します。
    • 仮想マシン名 – SQL Server VM の名前を入力します。
    • 仮想マシンのサイズ – 適切な VM サイズを選択します。
    • 仮想ネットワーク (VNet) – 既存の仮想ネットワークとサブネットを指定します。
    • SQL Server の構成 – イメージ オファー、SQL SKU、ストレージ ワークロードの設定を選択します。
    • 管理者の資格情報 - 管理者のユーザー名とパスワードを入力します。
  3. デプロイ パラメーターを確認します。

    パラメーター 型/既定値 使用できる値/制約 Description
    Subscription 必須 既存の Azure サブスクリプション デプロイに使用される Azure サブスクリプション。
    リソースグループ 必須 既存のリソース グループ SQL Server VM 用に準備されたリソース グループ。
    リージョン 既定値: resourceGroup().location Azureリージョン VM の Azure リージョン (米国中部など)。
    仮想マシン名 糸 1 ~ 15 文字 SQL Server 仮想マシンの名前。
    virtualMachineSize (バーチャルマシンサイズ) 糸 Azure VM のサイズ 仮想マシンのサイズ。
    existingVirtualNetworkName 糸 既存の仮想ネットワーク (VNet) 準備された仮想ネットワーク (VNet) の名前。
    既存Vnetリソースグループ 糸 既存のリソース グループ 仮想ネットワークを含むリソース グループ。
    existingSubnetName 糸 既存のサブネット 準備されたサブネットの名前。
    imageOffer 糸 SQL Server イメージと Windows Server イメージ SQL Server と Windows Server イメージ オファー。
    sqlSku 糸 Developer、Express、Standard、Enterprise SQL Server エディション SKU。
    adminUsername 糸 — VM の管理者ユーザー名。
    管理者パスワード セキュリティで保護された文字列 複雑さの強制 VM の管理者パスワード。
    ストレージワークロードタイプ 糸 OLTP、DW、General ストレージ ワークロードの種類 (OLTP = オンライン トランザクション処理、DW = データ ウェアハウス)。
    sqlDataDisksCount 整数 SKU あたりの最小/最大 SQL Server データ ファイルに使用されるディスクの数。
    データパス 糸 有効なパス SQL Server データ ファイルのパス。
    sqlLogDisksCount 整数 SKU あたりの最小/最大 SQL Server ログ ファイルに使用されるディスクの数。
    logPath 糸 有効なパス SQL Server ログ ファイルのパス。
    位置 既定値: resourceGroup().location Azureリージョン すべてのリソースの場所。
  4. [ 確認と作成] を選択し、[ 作成] を選択します。

  5. デプロイが成功したかどうかを確認します。

    • ポータル: デプロイの状態に [成功] と表示されていることを確認します。
    • Azure CLI:
      az resource show --resource-group <resource-group> --name <vm-name> --resource-type Microsoft.Compute/virtualMachines
      

テンプレートをデプロイするには Azure portal を使用します。 Azure portal に加えて、Azure PowerShell、Azure CLI、REST API も使用できます。 その他のデプロイ方法については、「テンプレートの デプロイ」を参照してください。

デプロイされているリソースを確認する

Azure CLI を使用して、デプロイされたリソースを確認できます。

echo "Enter the resource group where your SQL Server VM exists:" &&
read resourcegroupName &&
az resource list --resource-group $resourcegroupName 

リソースをクリーンアップする

不要になったら、Azure CLI または Azure PowerShell を使用してリソース グループを削除します。

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."

次のステップ

テンプレートを作成するプロセスを説明する詳細なチュートリアルについては、次を参照してください。

初めての ARM テンプレートを作成してデプロイする方法のチュートリアル

SQL Server VM をデプロイするその他の方法については、次を参照してください。

詳細については、 Azure VM 上の SQL Server の概要を参照してください。