az appservice plan コマンドとARM templateで、それぞれAppServiceプランを作成してみる。
詳細は適宜MSの公式ドキュメントのLinkを添付しておいたので、そちらも参照してみるとより理解が深まる。
大丈夫、この記事に書いている内容は全て無料枠だから、何度でも実施して確認することができる。

az appservice plan コマンドを使ったAppServiceプランの確認
既存AppServiceプランの確認。
方法は2つ。
- show:特定のリソースを表示
- list:条件に一致したリソースのリストを表示
show:特定のリソースを表示
単一のAppServiceプランを指定して表示する。
意図したリソースが表示されているかを確認する。
$> az appservice plan show --name masatoshuwFree --resource-group freeOnlyEastJ
{
"freeOfferExpirationTime": null,
"geoRegion": "Japan East",
"hostingEnvironmentProfile": null,
"hyperV": false,
"id": "/subscriptions/871e8b6f-0727-42ce-840e-02bf7d76541a/resourceGroups/freeOnlyEastJ/providers/Microsoft.Web/serverfarms/masatoshuwFree",
"isSpot": false,
"isXenon": false,
"kind": "linux",
"location": "Japan East",
"maximumElasticWorkerCount": 1,
"maximumNumberOfWorkers": 1,
"name": "masatoshuwFree",
"numberOfSites": 1,
"perSiteScaling": false,
"provisioningState": "Succeeded",
"reserved": true,
"resourceGroup": "freeOnlyEastJ",
"sku": {
"capabilities": null,
"capacity": 1,
"family": "F",
"locations": null,
"name": "F1",
"size": "F1",
"skuCapacity": null,
"tier": "Free"
},
"spotExpirationTime": null,
"status": "Ready",
"subscription": "871e8b6f-0727-42ce-840e-02bf7d76541a",
"systemData": null,
"tags": {},
"targetWorkerCount": 0,
"targetWorkerSizeId": 0,
"type": "Microsoft.Web/serverfarms",
"workerTierName": null
}
$>

list:条件に一致した複数のリソースをリスト表示
指定した条件に一致したリソースを配列要素としてリスト表示する。
条件は–queryパラメータで指定できる。
条件を指定しなければ、サブスクリプションに存在する全てのAppServiceプランが表示される。
$> az appservice plan list --query "[?sku.tier=='Free']"
[
{
"freeOfferExpirationTime": null,
"hostingEnvironmentProfile": null,
"hyperV": false,
"id": "/subscriptions/871e8b6f-0727-42ce-840e-02bf7d76541a/resourceGroups/freeOnlyEastJ/providers/Microsoft.Web/serverfarms/masatoshuwFree",
"isSpot": false,
"isXenon": false,
"kind": "linux",
"location": "Japan East",
"maximumElasticWorkerCount": 1,
"maximumNumberOfWorkers": 1,
"name": "masatoshuwFree",
"numberOfSites": 1,
"perSiteScaling": false,
"provisioningState": null,
"reserved": true,
"resourceGroup": "freeOnlyEastJ",
"sku": {
"capabilities": null,
"capacity": 1,
"family": "F",
"locations": null,
"name": "F1",
"size": "F1",
"skuCapacity": null,
"tier": "Free"
},
"spotExpirationTime": null,
"status": "Ready",
"systemData": null,
"tags": {},
"targetWorkerCount": 0,
"targetWorkerSizeId": 0,
"type": "Microsoft.Web/serverfarms",
"workerTierName": null
}
]
$>

az appservice planコマンドを使ったAppServiceプランの作成
skuにFree Tierを指定してAppServiceプランを作成する。
Freeプランは1リージョンに1つまでしか作成出来ないという制約があり、私はすでに東日本に1つFreeプランのAppServiceプランを持っているので、今回は西日本に作成する。
$> az appservice plan create --name masatoshuwfreeplan --resource-group freeOnlyWestJ --location japanwest --sku FREE --subscription PayAsYouGo-0520 --is-linux
{
"freeOfferExpirationTime": null,
"geoRegion": "Japan West",
"hostingEnvironmentProfile": null,
"hyperV": false,
"id": "/subscriptions/871e8b6f-0727-42ce-840e-02bf7d76541a/resourceGroups/freeOnlyWestJ/providers/Microsoft.Web/serverfarms/masatoshuwfreeplan",
"isSpot": false,
"isXenon": false,
"kind": "linux",
"location": "japanwest",
"maximumElasticWorkerCount": 1,
"maximumNumberOfWorkers": 0,
"name": "masatoshuwfreeplan",
"numberOfSites": 0,
"perSiteScaling": false,
"provisioningState": "Succeeded",
"reserved": true,
"resourceGroup": "freeOnlyWestJ",
"sku": {
"capabilities": null,
"capacity": 1,
"family": "U",
"locations": null,
"name": "U1",
"size": "U1",
"skuCapacity": null,
"tier": "LinuxFree"
},
"spotExpirationTime": null,
"status": "Ready",
"subscription": "871e8b6f-0727-42ce-840e-02bf7d76541a",
"systemData": null,
"tags": {},
"targetWorkerCount": 0,
"targetWorkerSizeId": 0,
"type": "Microsoft.Web/serverfarms",
"workerTierName": null
}
$>

気になったポイントはskuのtierが”LinuxFree”となっている事。
ミスったと思い、慌ててlistコマンドでfreeOnlyEastJ側のAppServiceプランと一緒にリスト表示して確認してみたが、”LinuxFree”ではなく”Free”に変わっていた。
そして特に違いなし。
これはよくわからないので、コマンドのバグ仕様ということで軽く「解決」にした。
$> az appservice plan list --query "[?sku.tier=='Free']"
[
{
"freeOfferExpirationTime": null,
"hostingEnvironmentProfile": null,
"hyperV": false,
"id": "/subscriptions/871e8b6f-0727-42ce-840e-02bf7d76541a/resourceGroups/freeOnlyWestJ/providers/Microsoft.Web/serverfarms/masatoshuwfreeplan",
"isSpot": false,
"isXenon": false,
"kind": "linux",
"location": "Japan West",
"maximumElasticWorkerCount": 1,
"maximumNumberOfWorkers": 1,
"name": "masatoshuwfreeplan",
"numberOfSites": 0,
"perSiteScaling": false,
"provisioningState": null,
"reserved": true,
"resourceGroup": "freeOnlyWestJ",
"sku": {
"capabilities": null,
"capacity": 1,
"family": "F",
"locations": null,
"name": "F1",
"size": "F1",
"skuCapacity": null,
"tier": "Free"
},
"spotExpirationTime": null,
"status": "Ready",
"systemData": null,
"tags": {},
"targetWorkerCount": 0,
"targetWorkerSizeId": 0,
"type": "Microsoft.Web/serverfarms",
"workerTierName": null
},
{
"freeOfferExpirationTime": null,
"hostingEnvironmentProfile": null,
"hyperV": false,
"id": "/subscriptions/871e8b6f-0727-42ce-840e-02bf7d76541a/resourceGroups/freeOnlyEastJ/providers/Microsoft.Web/serverfarms/masatoshuwFree",
"isSpot": false,
"isXenon": false,
"kind": "linux",
"location": "Japan East",
"maximumElasticWorkerCount": 1,
"maximumNumberOfWorkers": 1,
"name": "masatoshuwFree",
"numberOfSites": 1,
"perSiteScaling": false,
"provisioningState": null,
"reserved": true,
"resourceGroup": "freeOnlyEastJ",
"sku": {
"capabilities": null,
"capacity": 1,
"family": "F",
"locations": null,
"name": "F1",
"size": "F1",
"skuCapacity": null,
"tier": "Free"
},
"spotExpirationTime": null,
"status": "Ready",
"systemData": null,
"tags": {},
"targetWorkerCount": 0,
"targetWorkerSizeId": 0,
"type": "Microsoft.Web/serverfarms",
"workerTierName": null
}
]
$>
az appservice planコマンドを使ったAppServiceプランの削除
作成したAppServiceプランをAzure CLIで削除する。
$> az appservice plan delete --name masatoshuwfreeplan --resource-group freeOnlyWestJ --subscription PayAsYouGo-0520
Are you sure you want to perform this operation? (y/n): y
$>
–yesオプションを追加すると削除時の確認メッセージが表示されない。
また–subscriptionを指定しなければデフォルトのサブスクリプションが適用されるので、サブスクリプションが1つしか無いような環境であればこれも不要。
上記は–yesオプションを指定していない。理由は、–yesオプションがないとどのような確認メッセージになるのか気になったからだ。
例えば、「サブスクリプション=PayAsYouGo-0520のリソースグループ=freeOnlyWestJのAppServiceプラン=masatoshuwfreeplanは確かにあるけど、これを本当に削除するのか?」的なメッセージなら、一応削除処理前には確認してもいいかなと思ったのだ。
でもこんな確認メッセージなら、正直–yesオプションは毎回付けてもOKだなと思った。
ちなみに、MS公式ドキュメントでは–nameや–resource-groupも省略可能なオプションパラメータとなっているが、実際にはこの2つのパラメータは必須だった。
そりゃそうでしょ!
MSドキュメントに貢献したいのだが、どうすればこれを伝えられるだろうか。。
$> az appservice plan delete --name masatoshuwfreeplan
(--resource-group | --ids) are required
sato@[0:40:50]:~/projects/azure/template% az appservice plan delete --resource-group freeOnlyWestJ
(--name | --ids) are required
$>
ARM Templateを使用したAppServiceプランの作成(Resource Groupへのデプロイ)
Resource Groupのデプロイ時、az deployment subコマンドを使用し、指定のサブスクリプションへデプロイしたが、リソースのデプロイ時は、az deployment groupコマンドを使用して、指定のResource Groupへのデプロイを行う。
Templateファイル
テンプレートファイルにはResource Groupの指定がなく、az deployment groupコマンドのパラメータでResource Group名を指定する必要がある。
基本的に、templateファイルの作成は、慣れるまではAzure Portalで一度目的とするリソースを手動で作成してあら、テンプレートをエクスポートしたほうが早い。
変更箇所やパラメータ化すべき箇所を少し改修して利用するという方が効率的だ。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"serverfarms_masatoshuwfreeplan_name": {
"defaultValue": "masatoshuwfreeplan",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2018-02-01",
"name": "[parameters('serverfarms_masatoshuwfreeplan_name')]",
"location": "Japan West",
"tags": {
"owner": "masatoshuw"
},
"sku": {
"name": "F1",
"tier": "Free",
"size": "F1",
"family": "F",
"capacity": 1
},
"kind": "linux",
"properties": {
"perSiteScaling": false,
"maximumElasticWorkerCount": 1,
"isSpot": false,
"reserved": true,
"isXenon": false,
"hyperV": false,
"targetWorkerCount": 0,
"targetWorkerSizeId": 0
}
}
]
}
ARM TemplateでAppServiceプランを作成
$> az deployment group create --resource-group freeOnlyWestJ --template-file ./AppServicePlan.json
{
"id": "/subscriptions/871e8b6f-0727-42ce-840e-02bf7d76541a/resourceGroups/freeOnlyWestJ/providers/Microsoft.Resources/deployments/AppServicePlan",
"location": null,
"name": "AppServicePlan",
"properties": {
"correlationId": "a994e949-05ba-4b62-b696-c87400a38c24",
"debugSetting": null,
"dependencies": [],
"duration": "PT8.8561604S",
"error": null,
"mode": "Incremental",
"onErrorDeployment": null,
"outputResources": [
{
"id": "/subscriptions/871e8b6f-0727-42ce-840e-02bf7d76541a/resourceGroups/freeOnlyWestJ/providers/Microsoft.Web/serverfarms/masatoshuwfreeplan",
"resourceGroup": "freeOnlyWestJ"
}
],
"outputs": null,
"parameters": {
"serverfarms_masatoshuwfreeplan_name": {
"type": "String",
"value": "masatoshuwfreeplan"
}
},
"parametersLink": null,
"providers": [
{
"id": null,
"namespace": "Microsoft.Web",
"registrationPolicy": null,
"registrationState": null,
"resourceTypes": [
{
"aliases": null,
"apiProfiles": null,
"apiVersions": null,
"capabilities": null,
"defaultApiVersion": null,
"locationMappings": null,
"locations": [
"japanwest"
],
"properties": null,
"resourceType": "serverfarms",
"zoneMappings": null
}
]
}
],
"provisioningState": "Succeeded",
"templateHash": "4482970354493532908",
"templateLink": null,
"timestamp": "2021-08-01T16:01:01.335745+00:00",
"validatedResources": null
},
"resourceGroup": "freeOnlyWestJ",
"tags": null,
"type": "Microsoft.Resources/deployments"
}
$>
作成したリソースを確認
$> az appservice plan list --query "[?name=='masatoshuwfreeplan']"
[
{
"freeOfferExpirationTime": null,
"hostingEnvironmentProfile": null,
"hyperV": false,
"id": "/subscriptions/871e8b6f-0727-42ce-840e-02bf7d76541a/resourceGroups/freeOnlyWestJ/providers/Microsoft.Web/serverfarms/masatoshuwfreeplan",
"isSpot": false,
"isXenon": false,
"kind": "linux",
"location": "Japan West",
"maximumElasticWorkerCount": 1,
"maximumNumberOfWorkers": 1,
"name": "masatoshuwfreeplan",
"numberOfSites": 0,
"perSiteScaling": false,
"provisioningState": null,
"reserved": true,
"resourceGroup": "freeOnlyWestJ",
"sku": {
"capabilities": null,
"capacity": 1,
"family": "F",
"locations": null,
"name": "F1",
"size": "F1",
"skuCapacity": null,
"tier": "Free"
},
"spotExpirationTime": null,
"status": "Ready",
"systemData": null,
"tags": {
"owner": "masatoshuw"
},
"targetWorkerCount": 0,
"targetWorkerSizeId": 0,
"type": "Microsoft.Web/serverfarms",
"workerTierName": null
}
]
$>
作成したリソースを削除
$> az appservice plan delete --resource-group freeOnlyWestJ --name masatoshuwfreeplan --yes
$>
コメント