LoginSignup
5
5

More than 3 years have passed since last update.

Azure CLI コマンド例

Posted at

はじめに

これは、Azure CLI でよく使うものなどをメモしたものである。

準備

コマンド例

最初の一歩

  • ログイン

たとえば PowerShell で実行するとブラウザが起動し、そこから Azure のアカウントでログインする。
以下は PowerShell での実行例。(ただし各 ID は適当な値に変更してある)
homeTenantId の値が、規定のディレクトリのテナント ID にあたる。

PS C:\Users\hoge> az login
You have logged in. Now let us find all the subscriptions to which you have access...
The following tenants don't contain accessible subscriptions. Use 'az login --allow-no-subscriptions' to have tenant level access.
0301a880-bab5-4316-842b-1d81ca124eb2
b71a38d0-b08e-41e1-845b-1a1e0eb6e4e8
[
  {
    "cloudName": "AzureCloud",
    "homeTenantId": "19bdce1b-78d7-46e1-8fb8-4e735c6a02d4",
    "id": "34a01316-3b6f-4309-a9b1-4193b0ba4adf",
    "isDefault": true,
    "managedByTenants": [],
    "name": "subsc1",
    "state": "Enabled",
    "tenantId": "90b542a1-71a5-4995-9660-614f23b7a29d",
    "user": {
      "name": "hoge@example.com",
      "type": "user"
    }
  }
]
PS C:\Users\hoge>

サブスクリプション

  • サブスクリプション一覧の表示
az account list --output table
az account list -o table

リソースグループ

  • サブスクリプション内のリソース グループ 一覧の表示
az group list --output table
  • サブスクリプション内にリソースグループを作成
az group create  --name <resource-group-name> \
 --location <resource-group-location>

リソース

  • リソースグループ内のリソース一覧の表示(オプションとしてリソースタイプを指定)
az resource list --resource-group リソースグループ名 \
 --resource-type Microsoft.Web/sites
  • リソース一覧のうち、名前の列だけ取り出し
az resource list --query "[].{name:name}" -o table \
 --resource-type Microsoft.web/sites

ストレージアカウント

  • ストレージ アカウント 一覧
az storage account list -o table

ネットワーク

  • Azure DNS のゾーン一覧を JSON 形式で出力
az network dns zone list -o json

仮想サーバー

  • 作成(例として Ubuntu 16.04 , 管理者アカウント azureuser とする)
az vm create \
  --resource-group リソースグループ名 \
  --name 仮想サーバー名 \
  --image Canonical:UbuntuServer:16.04-LTS:latest \
  --admin-username azureuser \
  --generate-ssh-keys
  • ポート開放(例:後で作成する Web アプリに対し HTTP でアクセスできるようにする)
az vm open-port  --port 80 \
  --resource-group リソースグループ名 \
  --name 仮想サーバー名
  • 仮想サーバーの IP アドレス取得
ipaddress=$(az vm show \
   --name 仮想サーバー名 \
   --resource-group リソースグループ名 \
   --show-details \
   --query [publicIps] \
   --output tsv)

Web アプリ

  • Azure App Service で作成したWeb アプリの起動/停止
az webapp start --resource-group リソースグループ名 \
 --name <App Serviceのwebアプリ名>
az webapp stop --resource-group リソースグループ名 \
 --name <App Serviceのwebアプリ名>

以上。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5