More Related Content Similar to リソーステンプレート入門 (20) More from junichi anno (9) リソーステンプレート入門2. 2
VNET
VM
Storage
Compute
NIC
Private IP Public IP
SUBNET
仮想マシンをリソースに分解すると
Network Security Group
リソーステンプレートとして表現でき
るため、手順を意識することなく展開
することができる。
注意
リソースは“名前(Name)”属性で識
別されるため、企業内及びプロジェ
クト内での命名規約が重要である。
逆にいえば、リソーステンプレート
を見れば依存関係は一目瞭然。
6. 6
"parameters": {
"VNETName": {
"type": "string",
"metadata": {"description": "仮想ネットワークの名前"}
},
"VNETPrefix": {
"type": "string",
"metadata": {"description": "仮想ネットワークのIPレンジ(e.g. 10.0.0.0/16)"}
},
"SubnetName": {
"type": "string",
"metadata": {"description": "サブネット名"}
},
"SubnetPrefix" :{
"type": "string",
"metadata": {"description": "仮想ネットワークのIPレンジ(e.g. 10.0.0.0/24)"}
}
Parameters の書式について詳しくは
https://azure.microsoft.com/ja-jp/documentation/articles/resource-group-authoring-templates/
以下のParameters をAzureポータルに読み込ませると左の
ように表示される
8. 8
テンプレートの例❸ 仮想ネットワークを作成するーResources
"resources": [
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/virtualNetworks",
"name": "[parameters('VNETName')]",
"location": "[variables('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[parameters('VNETPrefix')]"
]
},
"subnets": [
{
"name": "[parameters('SubnetName')]",
"properties": {
"addressPrefix": "[parameters('SubnetPrefix')]"
}
}
]
}
}
]
• 作成するリソースを定義する
または 2014-06-01 を指定
仮想ネットワークのリソースタイプを表す
作成する仮想ネットワーク名。parameters から持ってきている
仮想ネットワークの作成場所。variables から持ってきている
仮想ネットワークの属性定義
アドレス空間の定義
アドレスのレンジ
Parameters から持ってきている
サブネットの定義
サブネットの名前。parameters から持ってきている。
サブネットの属性
サブネットのアドレスレンジ。parametersから持ってきている
9. 9
テンプレート例の全体像
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-
01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"VNETName": {
"type": "string",
"metadata": {"description": "仮想ネットワークの名前"}
},
"VNETPrefix": {
"type": "string",
"metadata": {"description": "仮想ネットワークのIPレンジ(e.g. 10.0.0.0/16)"}
},
"SubnetName": {
"type": "string",
"metadata": {"description": "サブネット名"}
},
"SubnetPrefix" :{
"type": "string",
"metadata": {"description": "仮想ネットワークのIPレンジ(e.g.
10.0.0.0/24)"}
}
},
"variables": {
"location": "[resourceGroup().location]",
},
"resources": [
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/virtualNetworks",
"name": "[parameters('VNETName')]",
"location": "[variables('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[parameters('VNETPrefix')]"
]
},
"subnets": [
{
"name": "[parameters('SubnetName')]",
"properties": {
"addressPrefix": "[parameters('SubnetPrefix')]"
}
}
]
}
}
]
}
http://aka.ms/seenpu からダウンロードできます
11. 11
Azure Portal を使用したテンプレートの展開手順
1. 「テンプレートのデプロイ」画面に移動
https://portal.azure.com/#create/Microsoft.Template
※2015.11.25時点ではメニューが用意されていない
2. 作成したテンプレートを読み込ませる
3. パラメタを指定する
4. サブスクリプションを指定
5. リソースグループを指定または作成
6. リソースグループの場所を指定
7. 法律条件に合意
8. 作成
20. 20
引数の定義
"parameters": {
"osMasterImageUri": {
"type": "string",
"metadata": {
"description": "マスターイメージのURI"
}
},
"vmName": {
"type": "string",
"metadata": {
"description": "仮想マシンの名前"
}
},
"osType": {
"type": "string",
"allowedValues": [
"Windows",
"Linux"
],
"defaultValue" :"Windows",
"metadata": {
"description": "OSのタイプ"
}
},
"adminUserName": {
"type": "string",
"metadata": {
"description": "管理者ユーザーID"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "管理者ユーザーIDのパスワード"
}
},
"vmSize": {
"type": "string",
"allowedValues": [
"Standard_A1",
"Standard_A2"
],
"defaultValue" :"Standard_A1",
"metadata": {
"description": "仮想マシンのサイズ"
}
},
"StorageAccountName": {
"type": "string",
"metadata": {
"description": "ストレージアカウントの名前"
}
},
"existingVirtualNetworkName": {
"type": "string",
"metadata": {
"description": "仮想ネットワーク"
}
},
"subnetName": {
"type": "string",
"metadata": {
"description": "サブネット名"
}
}
},
選択肢の設定
21. 21
変数の定義
"variables": {
"api-version": "2015-06-15",
"location": "[resourceGroup().location]",
"publicIPAddressType": "Dynamic",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', parameters('existingVirtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetID'),'/subnets/', parameters('subnetName'))]",
"nicName": "[concat(parameters('vmName'),'-nic')]",
"publicIPAddressName": "[concat(parameters('vmName'),'-pip')]",
“osDiskVhdName”: “[concat(‘http://’,parameters(‘StorageAccountName’),’.blob.core.windows.net/vhds/’,
parameters('vmName'),'osDisk.vhd')]"
},
resourceId 関数
• 書式 :resourceId( <リソースのタイプ> , <リソース名> )
• 戻り値 :指定したリソースの Id
22. 22
リソーステンプレート ~ Public IP の作成
{
"apiVersion": "[variables('api-version')]",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[variables('location')]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]"
}
}
Public IP のリソースタイプ
• Public IP の利用は課金対象でもあるため、独立したリ
ソースとして扱われる。
• ただし、リソースを作成しただけでは IP アドレスは
割り当てられないため課金されない。
※ variables() で指定されている変数は、Variables 句 で定義されている必要がある
23. 23
{
"apiVersion": "[variables('api-version')]",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[variables('location')]",
“dependsOn”: [ “[concat(‘Microsoft.Network/publicIPAddresses/’, variables(‘publicIPAddressName’))]” ],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
}
リソーステンプレート ~ NIC の作成
Public IP のリソースタイプ
依存関係の定義。ここで指定したリソースが作
成されていない場合には、NICも作成されない。
concat() は文字列の結合関数。
Private IP を動的に割り当てることを指定
既に作成した Public IP リソースを割り当てている
既存のリソースを表現する場合には resourceid(リソース
ID)関数を使用する。
NIC をどのサブネットに接続するかを指定
24. 24
リソーステンプレート ~ VM の作成❶
{
"apiVersion": "[variables('api-version')]",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"location": "[variables('location')]",
“dependsOn”: [ “[concat(‘Microsoft.Network/networkInterfaces/’, variables(‘nicName’))]” ],
(続く)
依存関係の定義。仮想マシンを作成する前に、NIC が作成さ
れていなければならない。
仮想マシンのリソースタイプ
25. 25
リソーステンプレート ~ VM の作成❷
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computername": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
}
ハードウェアのプロファイルを仮想マ
シンのサイズ(vmSize)で指定する
OSのプロファイルには、コンピュー
ター名、管理者のユーザーID、パス
ワードを指定する。
26. 26
リソーステンプレート ~ VM の作成❸
"storageProfile": {
"osDisk": {
"name": "[concat(parameters('vmName'),'-osDisk')]",
"osType": "[parameters('osType')]",
"caching": "ReadWrite",
"createOption": "FromImage",
"image": { "uri": "[parameters('osMasterImageUri')]" },
“vhd”: { "uri": "[variables('osDiskVhdName')]" }
}
},
ストレージのプロファイル
OSディスクを指定する
ディスクの名前となるプレフィックス。拡
張子はVHDになる。
OS のタイプ。Windows or Linux。
OSディスクのキャッシュ設定
ディスク作成のオプション。イメージから
作成することを示している。
マスターイメージの URI を指定する
OS ディスクの作成先をURIで指定する
28. 28
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"osMasterImageUri": {
"type": "string",
"metadata": {
"description": "マスターイメージのURI"
}
},
"vmName": {
"type": "string",
"metadata": {
"description": "仮想マシンの名前"
}
},
"osType": {
"type": "string",
"allowedValues": [
"Windows",
"Linux"
],
"defaultValue" :"Windows",
"metadata": {
"description": "OSのタイプ"
}
},
"adminUserName": {
"type": "string",
"metadata": {
"description": "管理者ユーザーID"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "管理者ユーザーIDのパスワード"
}
},
"vmSize": {
"type": "string",
"allowedValues": [
"Standard_A1",
"Standard_A2"
],
"defaultValue" :"Standard_A1",
"metadata": {
"description": "仮想マシンのサイズ"
}
},
"StorageAccountName": {
"type": "string",
"metadata": {
"description": "ストレージアカウントの名前"
}
},
"existingVirtualNetworkName": {
"type": "string",
"metadata": {
"description": "仮想ネットワーク"
}
},
"subnetName": {
"type": "string",
"metadata": {
"description": "サブネット名"
}
}
},
"variables": {
"api-version": "2015-06-15",
"location": "[resourceGroup().location]",
"publicIPAddressType": "Dynamic",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', parameters('existingVirtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetID'),'/subnets/', parameters('subnetName'))]",
"nicName": "[concat(parameters('vmName'),'-nic')]",
"publicIPAddressName": "[concat(parameters('vmName'),'-pip')]",
"osDiskVhdName":
"[concat('http://',parameters('StorageAccountName'),'.blob.core.windows.net/vhds/',parameters('vmName'),'
osDisk.vhd')]"
},
"resources": [
{
"apiVersion": "[variables('api-version')]",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[variables('location')]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]"
}
},
{
{
"apiVersion": "[variables('api-version')]",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[variables('location')]",
“dependsOn”: [ “[concat(‘Microsoft.Network/publicIPAddresses/’, variables(‘publicIPAddressName’))]” ],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
}
},
{
"apiVersion": "[variables('api-version')]",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"location": "[variables('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computername": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"osDisk": {
"name": "[concat(parameters('vmName'),'-osDisk')]",
"osType": "[parameters('osType')]",
"caching": "ReadWrite",
"createOption": "FromImage",
"image": {
"uri": "[parameters('osMasterImageUri')]"
},
"vhd": {
"uri": "[variables('osDiskVhdName')]"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
}
}
}
]
}
http://aka.ms/fw5w5u からダウンロード可能