AzureCLI 設定等メモ

AzureCLIを使う際のメモ書き

基本的には[公式情報](https://docs.microsoft.com/ja-jp/cli/azure/?view=azure-cli-latest)をみればよい

# (Windows)AzureCLIのインストール

1.管理者権限でpowershellを開く
2.以下のコマンドを入力

```powershell:input
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'
```

3.インストール完了したらpowershellを再度開く
4.動作確認

```powershell:input
az -v
```


```powershell:output
azure-cli                         2.0.75

command-modules-nspkg              2.0.3
core                              2.0.75
nspkg                              3.0.4
telemetry                          1.0.4

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Users\user\.azure\cliextensions'

Python (Windows) 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 02:47:15) [MSC v.1900 32 bit (Intel)]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.
```

# AzureCLIでのログイン

## 対話形式でのログイン
```powershell:input
az login
```

```powershell:output
Note, we have launched a browser for you to login. For old experience with device code, use "az login --use-device-code"
# ブラウザが自動で開くのでログイン操作
You have logged in. Now let us find all the subscriptions to which you have access...
[
  {
    "cloudName": "AzureCloud",
    "id": "*************",
    "isDefault": true,
    "name": "Pay-As-You-Go",
    "state": "Enabled",
    "tenantId": "*********************",
    "user": {
      "name": "**********************",
      "type": "user"
    }
  }
]
```

## コマンド形式でのログイン

```powershell:input
az login -u <username> -p <password>
```

# location情報の取得

AzureCLIを使う際のlocation名称の取得コマンド
基本的に`japaneast`を使うことが多いですが、他locationを選択する際に便利

```powershell:input
az account list-locations --output table
```

```powershell:output
DisplayName           Latitude    Longitude    Name
--------------------  ----------  -----------  ------------------
East Asia             22.267      114.188      eastasia
Southeast Asia        1.283       103.833      southeastasia
Central US            41.5908     -93.6208     centralus
East US               37.3719     -79.8164     eastus
East US 2             36.6681     -78.3889     eastus2
West US               37.783      -122.417     westus
North Central US      41.8819     -87.6278     northcentralus
South Central US      29.4167     -98.5        southcentralus
North Europe          53.3478     -6.2597      northeurope
West Europe           52.3667     4.9          westeurope
Japan West            34.6939     135.5022     japanwest
Japan East            35.68       139.77       japaneast
Brazil South          -23.55      -46.633      brazilsouth
Australia East        -33.86      151.2094     australiaeast
Australia Southeast   -37.8136    144.9631     australiasoutheast
South India           12.9822     80.1636      southindia
Central India         18.5822     73.9197      centralindia
West India            19.088      72.868       westindia
Canada Central        43.653      -79.383      canadacentral
Canada East           46.817      -71.217      canadaeast
UK South              50.941      -0.799       uksouth
UK West               53.427      -3.084       ukwest
West Central US       40.890      -110.234     westcentralus
West US 2             47.233      -119.852     westus2
Korea Central         37.5665     126.9780     koreacentral
Korea South           35.1796     129.0756     koreasouth
France Central        46.3772     2.3730       francecentral
France South          43.8345     2.1972       francesouth
Australia Central     -35.3075    149.1244     australiacentral
Australia Central 2   -35.3075    149.1244     australiacentral2
UAE Central           24.466667   54.366669    uaecentral
UAE North             25.266666   55.316666    uaenorth
South Africa North    -25.731340  28.218370    southafricanorth
South Africa West     -34.075691  18.843266    southafricawest
Switzerland North     47.451542   8.564572     switzerlandnorth
Switzerland West      46.204391   6.143158     switzerlandwest
Germany North         53.073635   8.806422     germanynorth
Germany West Central  50.110924   8.682127     germanywestcentral
Norway West           58.969975   5.733107     norwaywest
Norway East           59.913868   10.752245    norwayeast

```

# 出力形式の指定

AzureCLIでは標準入力がJSONだが、必要に応じて出力内容を変更可能
`--output` `--out` `--o` `-o`どれでもOK
対応する出力形式は以下表

|--output|説明|
|---|---|
|json|JSON文字列　既定値|
|jsonc|色付きのJSON|
|yaml|YAML形式|
|table|人が見やすいテーブル形式|
|tsv|タブ区切りの値|

## 既定の出力形式の変更

既定出力形式は変更することが可能

```powershell:input
az configure
```

```powershell:output
Welcome to the Azure CLI! This command will guide you through logging in and setting some default values.

Your settings can be found at C:\Users\user\.azure\config
Your current configuration is as follows:

[cloud]
name = AzureCloud

[core]
first_run = yes

Do you wish to change your settings? (y/N): y

What default output format would you like?
 [1] json - JSON formatted output that most closely matches API responses.
 [2] jsonc - Colored JSON formatted output that most closely matches API responses.
 [3] table - Human-readable output format.
 [4] tsv - Tab- and Newline-delimited. Great for GREP, AWK, etc.
 [5] yaml - YAML formatted output. An alternative to JSON. Great for configuration files.
 [6] none - No output, except for errors and warnings.
Please enter a choice [Default choice(1)]:
```