なんかつてで教えてもらったのでメモを。
azureのcliのハンズオン
・Dockerとpythonとbashが入ってないといけないらしい(azコマンドを使うための仕込み)
※最近はCloud Shellとかつかうとボタンポチっとするだけでazもterraformも入ってるコンソールを使えるようです。
https://docs.microsoft.com/ja-jp/azure/cloud-shell/persisting-shell-storage
Unix系だと以下のようにできる模様
python --version
pip install --user azure-cli
か
curl -L https://aka.ms/InstallAzureCli | bash
Winだと環境変数に左右されたりする模様
(バーチャライゼーションをBIOSで有効化するのと署名をごにょごにょする必要ある)
・dockerが入ったらazuresdkいれる
docker run -it azuresdk/azure-cli-python:latest
↑のコマンドでDockerイメージがローカルになければDLされ、
-it によって Docker コンテナ内にログインして操作できる、という感じです
GitHub のドキュメントでは -v でローカルのディスクにアタッチしてますが、そこは必要に応じて。
azが使えるようになってる環境にて
・バージョンを確認
$ az --version
azure-cli (2.0.2)
・ログインする
ログイン打つとURLとコードがでてくるのでそこにアクセスしてコードを入力すると自動的に自分のアカウントのログイン画面に遷移し、ログインする(二段階認証あり)とjsonで紐づいてるテナントIDなどが返ってくる
$ az login
To sign in, use a web browser to open the page https://aka.ms/devicelogin and enter the code GUW5SQUQA to authenticate.
表示されたURLを開いて表示されたコードを入力するとログインできた情報がコンソールに表示される
アカウントをリストで確認することが可能になっている
$ az account list -o table
主に使うアカウントをセットする
$ az account set --help
Command
az account set: Set a subscription as the current subscription.
Arguments
--subscription [Required]: Name or ID of subscription.
Global Arguments
--debug : Increase logging verbosity to show all debug logs.
--help -h : Show this help message and exit.
--output -o : Output format. Allowed values: json, jsonc, table, tsv. Default:
json.
--query : JMESPath query string. See http://jmespath.org/ for more information
and examples.
--verbose : Increase logging verbosity. Use --debug for full debug logs.
$ az account set --subscription <mysubscription>
$ az account show
・リソースグループを作成する
$ az group create -n komiya-azcli-test-grp -l japaneast
・ネットワークをつくる
$ az network vnet create -g komiya-azcli-test-grp -n komi-ctest-vnet --address-prefixes 10.0.0.0/16 -l japaneast
・サブネットを作る
$ az network vnet subnet create -n komi-ctest-subnet1-pub -g komiya-azcli-test-grp --vnet-name komi-ctest-vnet --address-prefix 10.0.0.0/24
・パブリックIPを作る
$ az network public-ip create -g komiya-azcli-test-grp -n komi-ctest-pip1 -l japaneast
・ニックを作る
$ az network nic create -g komiya-azcli-test-grp -n komi-ctest-nic1 -l japaneast --private-ip-address 10.0.0.10 --subnet komi-ctest-subnet1-pub --vnet-name komi-ctest-vnet
・VMを作る
$ az vm create -g komiya-azcli-test-grp -n komi-ctest-vm1 -l japaneast --image Win2016Datacenter --size Standard_DS1 --nics komi-ctest-nic1 --admin-username komiyay --admin-password ***************
publicIPをつけ忘れた
$ az network nic ip-config list \
> -g komiya-azcli-test-grp \
> --nic-name komi-ctest-nic1 \
> --query "[?provisioningState=='Succeeded'].{ Name: name, PublicIpAddressId: publicIpAddress.id }" --output table
Name
---------
ipconfig1
$ az network nic ip-config update \
> -g komiya-azcli-test-grp \
> --nic-name komi-ctest-nic1 \
> --name ipconfig1 \
> --public-ip komi-ctest-pip1
$ az network nic ip-config list -g komiya-azcli-test-grp --nic-name komi-ctest-nic1 --query "[?provisioningState=='Succeeded'].{ Name: name, PublicIpAddressId: publicIpAddress.id }" --output table
Name PublicIpAddressId
--------- ------------------------------------------------------------------------------------------------------------------------------------------------------
ipconfig1 /subscriptions/43ffcbd3-6551-48d5-b08f-51953afbxxxx/resourceGroups/komiya-azcli-test-grp/providers/Microsoft.Network/publicIPAddresses/komi-ctest-pip1
いけたっぽい。
$ az vm show -n komi-ctest-vm1 -g komiya-azcli-test-grp -d
まとめると以下のとおり
・ログイン
サブスクリプションを指定する
・リソースグループつくる
・Vnetつくる
・サブネットつくる
・IPつくる
・nicつくる
・VMつくる
デフォルトでRDPのポートは開いてるので必要に応じてSecrityGroupつくって紐づける
az vm
パブリックIPにRDPして確認する
→できた
・リソースを消す
テストの場合にはリソースグループ消すと丸ごときえて話が早いらしい。
az group delete -n (リソースグループ名)
ということで今日のところはここまで。