templateファイルの用意
1 2 3 4 5 |
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "resources": [] } |
準備
ログイン
1 2 3 |
az group create <span class="se">\</span> <span class="nt">--name</span> myResourceGroup <span class="se">\</span> <span class="nt">--location</span> <span class="s2">"Central US"</span> |
デプロイ
1 2 3 4 5 |
<span class="nv">templateFile</span><span class="o">=</span><span class="s2">"azuredeply.json"</span> az deployment group create <span class="se">\</span> <span class="nt">--name</span> blanktemplate <span class="se">\</span> <span class="nt">--resource-group</span> myResourceGroup <span class="se">\</span> <span class="nt">--template-file</span> <span class="nv">$templateFile</span> |
出力
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
{- Finished .. "id": "/subscriptions/9611116b-ea93-42fc-bc7a-6a1149bb2521/resourceGroups/myResourceGroup/providers/Microsoft.Resources/deployments/blanktemplate", "location": null, "name": "blanktemplate", "properties": { "correlationId": "3f74a43b-73e3-4032-88e1-a1d00d2493ee", "debugSetting": null, "dependencies": [], "duration": "PT3.036297S", "mode": "Incremental", "onErrorDeployment": null, "outputResources": [], "outputs": null, "parameters": null, "parametersLink": null, "providers": [], "provisioningState": "Succeeded", "template": null, "templateHash": "11481920352792298114", "templateLink": null, "timestamp": "2020-07-10T07:02:13.126846+00:00" }, "resourceGroup": "myResourceGroup", "type": "Microsoft.Resources/deployments" } |
動作確認
Azure Portalからデプロイの確認ができる
リソースの追加
- ストレージアカウントの作成
- ストレージアカウント名はユニーク名
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<span class="p">{</span> <span class="nl">"$schema"</span><span class="p">:</span> <span class="s2">"https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#"</span><span class="p">,</span> <span class="nl">"contentVersion"</span><span class="p">:</span> <span class="s2">"1.0.0.0"</span><span class="p">,</span> <span class="nl">"resources"</span><span class="p">:</span> <span class="p">[</span> <span class="p">{</span> <span class="nl">"type"</span><span class="p">:</span> <span class="s2">"Microsoft.Storage/storageAccounts"</span><span class="p">,</span> <span class="nl">"apiVersion"</span><span class="p">:</span> <span class="s2">"2019-04-01"</span><span class="p">,</span> <span class="nl">"name"</span><span class="p">:</span> <span class="s2">"armstoragetest0910"</span><span class="p">,</span> <span class="nl">"location"</span><span class="p">:</span> <span class="s2">"eastus"</span><span class="p">,</span> <span class="nl">"sku"</span><span class="p">:</span> <span class="p">{</span> <span class="nl">"name"</span><span class="p">:</span> <span class="s2">"Standard_LRS"</span> <span class="p">},</span> <span class="nl">"kind"</span><span class="p">:</span> <span class="s2">"StorageV2"</span><span class="p">,</span> <span class="nl">"properties"</span><span class="p">:</span> <span class="p">{</span> <span class="nl">"supportsHttpsTrafficOnly"</span><span class="p">:</span> <span class="kc">true</span> <span class="p">}</span> <span class="p">}</span> <span class="p">]</span> <span class="p">}</span> |
再デプロイ
1 2 3 4 |
az deployment group create <span class="se">\</span> <span class="nt">--name</span> blanktemplate <span class="se">\</span> <span class="nt">--resource-group</span> myResourceGroup <span class="se">\</span> <span class="nt">--template-file</span> <span class="nv">$templateFile</span> |
動作確認
ストレージアカウントが作成されている
パラメータ追加
- ストレージ名を変数化
"name": "[parameters('storageName')]",
のような感じに
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<span class="p">{</span> <span class="nl">"$schema"</span><span class="p">:</span> <span class="s2">"https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#"</span><span class="p">,</span> <span class="nl">"contentVersion"</span><span class="p">:</span> <span class="s2">"1.0.0.0"</span><span class="p">,</span> <span class="nl">"parameters"</span><span class="p">:</span> <span class="p">{</span> <span class="nl">"storageName"</span><span class="p">:</span> <span class="p">{</span> <span class="nl">"type"</span><span class="p">:</span> <span class="s2">"string"</span><span class="p">,</span> <span class="nl">"minLength"</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="nl">"maxLength"</span><span class="p">:</span> <span class="mi">24</span> <span class="p">}</span> <span class="p">},</span> <span class="nl">"resources"</span><span class="p">:</span> <span class="p">[</span> <span class="p">{</span> <span class="nl">"type"</span><span class="p">:</span> <span class="s2">"Microsoft.Storage/storageAccounts"</span><span class="p">,</span> <span class="nl">"apiVersion"</span><span class="p">:</span> <span class="s2">"2019-04-01"</span><span class="p">,</span> <span class="nl">"name"</span><span class="p">:</span> <span class="s2">"[parameters('storageName')]"</span><span class="p">,</span> <span class="nl">"location"</span><span class="p">:</span> <span class="s2">"eastus"</span><span class="p">,</span> <span class="nl">"sku"</span><span class="p">:</span> <span class="p">{</span> <span class="nl">"name"</span><span class="p">:</span> <span class="s2">"Standard_LRS"</span> <span class="p">},</span> <span class="nl">"kind"</span><span class="p">:</span> <span class="s2">"StorageV2"</span><span class="p">,</span> <span class="nl">"properties"</span><span class="p">:</span> <span class="p">{</span> <span class="nl">"supportsHttpsTrafficOnly"</span><span class="p">:</span> <span class="kc">true</span> <span class="p">}</span> <span class="p">}</span> <span class="p">]</span> <span class="p">}</span> |
再デプロイ
1 2 3 4 5 |
az deployment group create <span class="se">\</span> <span class="nt">--name</span> addskuparameter <span class="se">\</span> <span class="nt">--resource-group</span> myResourceGroup <span class="se">\</span> <span class="nt">--template-file</span> <span class="nv">$templateFile</span> <span class="se">\</span> <span class="nt">--parameters</span> <span class="nv">storageName</span><span class="o">=</span>azurearmtest2 |
動作確認