LoginSignup
3

More than 5 years have passed since last update.

Azure CLIで複数のサブスクリプションを切り替える

Posted at

Azureアドベントカレンダー11日目!ということでAzureでニッチなところの話です。

ちなみに 「【1周年・合宿】集まれSwift好き!Swift愛好会 vol13」の合宿でちまちま書いてます笑

azure cliを使ってておきた話です。
複数サブスクリプションを持ってない人にはほぼ関係ないです苦笑

入れてない人は以下でインストールできます。

npm i -g azure

ログイン方法などは過去の記事参照でお願いします。

AzureのCLIツールを使ってCoreOS/Docker上にWebサーバーを立ててみる。

おきた症状

mydevリソースグループのWebAppsアプリケーション一覧を取得したいと思ったらエラー吐かれました。

$ azure webapp list mydev
info:    Executing command webapp list
+ Listing webapps
error:   Resource group 'mydev' could not be found.
error:   Error information has been recorded to /Users/n0bisuke/.azure/azure.err
error:   webapp list command failed

どうやら複数のサブスクリプションを持ってると、一つ目のサブスクリプションに紐づけられてるリソースグループしか読み込んでくれないみたいです。

解決方法

Azure CLI から Azure へのログイン > 複数のサブスクリプション」に解決方法がありました。

azure account listazure account set <サブスクリプション>というコマンドで切り替えできます。

$ azure account list

azure account list
info:    Executing command account list
data:    Name                                Id                                    Current  State
data:    ----------------------------------  ------------------------------------  -------  -------
data:    Microsoft Azure xxxxxx プラン        xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx   true   Enabled
data:    Visual Studio Enterprise: BizSpark  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  false     Enabled
info:    account list command OK

currentがtrueになっているのが現在有効になっているサブスクリプションです。
Visual Studio Enterprise: BizSparkに切り替える場合は以下のようにします。

$ azure account set "Visual Studio Enterprise: BizSpark"

info:    Executing command account set
info:    Setting subscription to "Visual Studio Enterprise: BizSpark" with id "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".
info:    Changes saved
info:    account set command OK

これで切り替えられました。

最初にやろうとしたWebAppsのリストを取ってみます。

$ azure webapp list mydev
info:    Executing command webapp list
+ Listing webapps
data:
data:    Web App Name     : myapp1
data:    Enabled          : true
data:    Status           : Running
data:    Last Modified    : 2016-11-05T08:36:27.397Z
data:    Location         : Japan East
data:    App Service Plan : kantoS1
+ Checking for slots
data:
data:    Web App Name     : myapp2
data:    Enabled          : true
data:    Status           : Running
data:    Last Modified    : 2016-12-04T02:34:43.840Z
data:    Location         : West Europe
data:    App Service Plan : ServicePlan92ec976d-xxxx
+ Checking for slots
info:    webapp list command OK

無事に取得できました!

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
3