2016年11月5日土曜日

SCOMのAzure Resource Manager VM Templete

データディスク8本を記憶域プールで束ねて、SCOMのバイナリーやDBを置くドライブとしているラボを構成しています。
新規作成から、データディスク8本を追加するのがだんだん面倒になりました。。。

そこで、SCOMのAzure Resource Manager VM Templeteを書いてみました。
ベースは、
githubのAzure Resource Manager テンプレートをカスタマイズしてみた - RDP接続できるVMテンプレート
です。

テンプレートをデプロイする際の前提は、リソースグループ、ストレージアカウント、仮想ネットワークは、構築済みであること。

今後の改善事項は、NICにDNSサーバー設定を入れ込むことでしょうか。

デプロイの画面。

実際にデプロイ後、ディスクの管理で確認。

記憶域プールでディスクをまとめたところ。


では、コードを下記に掲載しておきます。
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "type": "string",
      "defaultValue": "arscom2016",
      "metadata": {
        "description": "name for the Virtual Machine."
      }
    },
    "dnsLabelPrefix": {
      "type": "string",
      "defaultValue": "arscom2016",
      "metadata": {
        "description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
      }
    },
    "adminUsername": {
      "type": "string",
      "metadata": {
        "description": "Username for the Virtual Machine."
      }
    },
    "adminPassword": {
      "type": "securestring",
      "metadata": {
        "description": "Minimum 12 characters. Password for the Virtual Machine."
      }
    },
    "windowsOSVersion": {
      "type": "string",
      "defaultValue": "2016-Datacenter",
      "allowedValues": [
        "2012-R2-Datacenter"
        "2016-Datacenter"
      ],
      "metadata": {
        "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version. Allowed values: 2012-R2-Datacenter, 2016-Datacenter."
      }
    },
    "vmSize": {
      "type": "string",
      "defaultValue": "Standard_DS3",
      "allowedValues": [
        "Standard_DS3_v2",
        "Standard_DS3"
      ]
    },
    "vmDataDiskSize": {
      "type": "int",
      "defaultValue": 33
    },
    "rdpFrontend": {
      "type": "int",
      "defaultValue": 50001,
      "metadata": {
        "description": "Public port number for RDP"
      }
    },
    "VNetName": {
      "type": "string",
      "defaultValue": "arejpVNet1"
    },
    "VSubnetName": {
      "type": "string",
      "defaultValue": "Subnet"
    },
    "storageAccountName": {
      "type": "string",
      "defaultValue": "arejpstorageact0"
    }
  },
  "variables": {
    "sizeOfDiskInGB": "[parameters('vmDataDiskSize')]",
    "imagePublisher": "MicrosoftWindowsServer",
    "imageOffer": "WindowsServer",
    "vmName": "[parameters('vmName')]",
    "vmSize": "[parameters('vmSize')]",
    "OSDiskName": "[concat(variables('vmName'),'-os')]",
    "dataDisk1VhdName": "[concat(variables('vmName'),'-data1')]",
    "dataDisk2VhdName": "[concat(variables('vmName'),'-data2')]",
    "dataDisk3VhdName": "[concat(variables('vmName'),'-data3')]",
    "dataDisk4VhdName": "[concat(variables('vmName'),'-data4')]",
    "dataDisk5VhdName": "[concat(variables('vmName'),'-data5')]",
    "dataDisk6VhdName": "[concat(variables('vmName'),'-data6')]",
    "dataDisk7VhdName": "[concat(variables('vmName'),'-data7')]",
    "dataDisk8VhdName": "[concat(variables('vmName'),'-data8')]",
    "nicName": "[concat(variables('vmName'),'-nic01')]",
    "existingVNetName": "[parameters('VNetName')]",
    "subnetName": "[parameters('VSubnetName')]",
    "publicIPAddressName": "[concat(variables('vmName'),'-PublicIP01')]",
    "publicIPAddressType": "Dynamic",
    "vmStorageAccountContainerName": "[concat(variables('vmName'),'-vhds')]",
    "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('existingVNetName'))]",
    "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
    "lbName": "[concat(parameters('vmName'),'-lb01')]",
    "lbInboundNatRulesName": "[concat(parameters('vmName'),variables('lbName'),'-InboundNatRules01')]",
    "lbFrontEndName": "[concat(parameters('vmName'),variables('lbName'),'-FrontEnd01')]",
    "lbBackendAddressPoolName": "[concat(parameters('vmName'),variables('lbName'),'-BackendPool01')]",
    "publicIPAddressID": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]",
    "lbID": "[resourceId('Microsoft.Network/loadBalancers',variables('lbName'))]",
    "lbFrontEndIPConfigID": "[concat(variables('lbID'),'/frontendIPConfigurations/',variables('lbFrontEndName'))]",
    "lbPoolID": "[concat(variables('lbID'),'/backendAddressPools/',variables('lbBackendAddressPoolName'))]",
    "lbNatID": "[concat(variables('lbID'),'/inboundNatRules/',variables('lbInboundNatRulesName'))]",
    "apiVersion": "2015-06-15"
  },
  "resources": [
    {
      "apiVersion": "[variables('apiVersion')]",
      "type": "Microsoft.Network/publicIPAddresses",
      "name": "[variables('publicIPAddressName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "publicIPAllocationMethod": "[variables('publicIPAddressType')]",
        "dnsSettings": {
          "domainNameLabel": "[parameters('dnsLabelPrefix')]"
        }
      }
    },
    {
      "apiVersion": "[variables('apiVersion')]",
      "name": "[variables('lbName')]",
      "type": "Microsoft.Network/loadBalancers",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
      ],
      "properties": {
        "frontendIPConfigurations": [
          {
            "name": "[variables('lbFrontEndName')]",
            "properties": {
              "publicIPAddress": {
                "id": "[variables('publicIPAddressID')]"
              }
            }
          }
        ],
        "backendAddressPools": [
          {
            "name": "[variables('lbBackendAddressPoolName')]"
          }
        ],
        "inboundNatRules": [
          {
            "name": "[variables('lbInboundNatRulesName')]",
            "properties": {
              "frontendIPConfiguration": {
                "id": "[variables('lbFrontEndIPConfigID')]"
              },
              "protocol": "tcp",
              "frontendPort": "[parameters('rdpFrontend')]",
              "backendPort": 3389,
              "enableFloatingIP": false
            }
          }
        ]
      }
    },
    {
      "apiVersion": "[variables('apiVersion')]",
      "type": "Microsoft.Network/networkInterfaces",
      "name": "[variables('nicName')]",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Network/loadBalancers/',variables('lbName'))]"
      ],
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "privateIPAllocationMethod": "Dynamic",
              "subnet": {
                "id": "[variables('subnetRef')]"
              },
              "loadBalancerBackendAddressPools": [
                {
                  "id": "[variables('lbPoolID')]"
                }
              ],
              "loadBalancerInboundNatRules": [
                {
                  "id": "[variables('lbNatID')]"
                }
              ]
            }
          }
        ]
      }
    },
    {
      "apiVersion": "[variables('apiVersion')]",
      "type": "Microsoft.Compute/virtualMachines",
      "name": "[variables('vmName')]",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
      ],
      "properties": {
        "hardwareProfile": {
          "vmSize": "[variables('vmSize')]"
        },
        "osProfile": {
          "computerName": "[variables('vmName')]",
          "adminUsername": "[parameters('adminUsername')]",
          "adminPassword": "[parameters('adminPassword')]"
        },
        "storageProfile": {
          "imageReference": {
            "publisher": "[variables('imagePublisher')]",
            "offer": "[variables('imageOffer')]",
            "sku": "[parameters('windowsOSVersion')]",
            "version": "latest"
          },
          "osDisk": {
            "name": "[variables('OSDiskName')]",
            "vhd": {
              "uri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]"
            },
            "caching": "ReadWrite",
            "createOption": "FromImage"
          },
          "dataDisks": [
            {
              "name": "[variables('dataDisk1VhdName')]",
              "diskSizeGB": "[variables('sizeOfDiskInGB')]",
              "lun": 0,
              "vhd": {
                "uri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('dataDisk1VhdName'),'.vhd')]"
              },
              "createOption": "Empty"
            },
            {
              "name": "[variables('dataDisk2VhdName')]",
              "diskSizeGB": "[variables('sizeOfDiskInGB')]",
              "lun": 1,
              "vhd": {
                "uri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('dataDisk2VhdName'),'.vhd')]"
              },
              "createOption": "Empty"
            },
            {
              "name": "[variables('dataDisk3VhdName')]",
              "diskSizeGB": "[variables('sizeOfDiskInGB')]",
              "lun": 2,
              "vhd": {
                "uri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('dataDisk3VhdName'),'.vhd')]"
              },
              "createOption": "Empty"
            },
            {
              "name": "[variables('dataDisk4VhdName')]",
              "diskSizeGB": "[variables('sizeOfDiskInGB')]",
              "lun": 3,
              "vhd": {
                "uri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('dataDisk4VhdName'),'.vhd')]"
              },
              "createOption": "Empty"
            },
            {
              "name": "[variables('dataDisk5VhdName')]",
              "diskSizeGB": "[variables('sizeOfDiskInGB')]",
              "lun": 4,
              "vhd": {
                "uri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('dataDisk5VhdName'),'.vhd')]"
              },
              "createOption": "Empty"
            },
            {
              "name": "[variables('dataDisk6VhdName')]",
              "diskSizeGB": "[variables('sizeOfDiskInGB')]",
              "lun": 5,
              "vhd": {
                "uri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('dataDisk6VhdName'),'.vhd')]"
              },
              "createOption": "Empty"
            },
            {
              "name": "[variables('dataDisk7VhdName')]",
              "diskSizeGB": "[variables('sizeOfDiskInGB')]",
              "lun": 6,
              "vhd": {
                "uri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('dataDisk7VhdName'),'.vhd')]"
              },
              "createOption": "Empty"
            },
            {
              "name": "[variables('dataDisk8VhdName')]",
              "diskSizeGB": "[variables('sizeOfDiskInGB')]",
              "lun": 7,
              "vhd": {
                "uri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('dataDisk8VhdName'),'.vhd')]"
              },
              "createOption": "Empty"
            }
          ]
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
            }
          ]
        },
        "diagnosticsProfile": {
          "bootDiagnostics": {
            "enabled": "true",
            "storageUri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net')]"
          }
        }
      }
    }
  ]
}

0 件のコメント:

コメントを投稿