LoginSignup
3
0

More than 1 year has passed since last update.

Azure Administrator(AZ-104):Azure管理者向けの前提条件「Azure CLIによるAzureリソースの作成」

Last updated at Posted at 2022-12-16

Microsoft Learnを用いたMicrosoft Azure Administrator(AZ-104)の試験内容をまとめる投稿です。
この投稿ではMicrosoft Learnで学ぶ内容をできるだけ簡潔にまとめております。
Azureの勉強を一から始め、AZ-900取得後の資格としてAZ-104取得を目指している方の参考になれば幸いです。
※AZ-900の内容は本投稿では省略しております。再度復習したい方は下記をご参照ください。
Azure Fundamentals(AZ-900):試験合格に向けた学習内容のまとめ

今回の学習内容

◆「Azure Cloud Shell の使用」
◇対応するMicrosoft Learn ラーニングパス
AZ-104:Azure 管理者向けの前提条件
◇対応するモジュール
Azure CLI を使用する

※前回の投稿は下記から確認できます。
Azure Administrator(AZ-104):Azure管理者向けの前提条件「Azure CLIとスクリプト」

Azure CLIによるAzureリソースの作成

Azureリソースの作成

  1. サブスクリプションへの接続
  2. サブスクリプションの確認と接続の変更
  3. リソースグループの確認と作成
  4. リソースの作成
  5. 作成したリソースの確認

◆Azureリソース作成のコマンド例(詳細は後述)
例)MS-Learnのサンドボックスで仮想マシンを作成する場合
※VMの作成がポリシーで許可されている下記サンドボックスの使用をおすすめします。
演習 - Azure PowerShell でスクリプトを使用して Azure リソースを作成する

Azure CLI
az login
az account show
az account set --name "Concierge Subscription"
az group list --output table
export RSGroup="[ResourceGroup名]"
az vm create \
 --name "testvm-eus-01" \
 --resource-group $RSGroup \
 --admin-username "[ログイン用ユーザ名]" \
 --admin-password "[ログイン用パスワード]" \
 --location "East US" \
 --image UbuntuLTS \
 --public-ip-address "testvm-01"
az vm list -g $RSGroup -d -o table

サブスクリプションへの接続

①Azure CLI上で「az login」を入力すると、ブラウザにてAzure認証画面が表示

Azure CLI
az login

image.png
②アカウントを選択すると認証が行われ、認証に成功するとブラウザに下記が出力
 You have logged into Microsoft Azure!
 You can close this window, or we will redirect you to the Azure CLI documentation in 10 seconds.

③接続が完了し、選択したアカウントに紐づくサブスクリプションがAzure CLI上に出力
image.png

サブスクリプションの確認と接続の変更

④Azure CLI上で「az account show」を入力し、現在接続しているサブスクリプションを表示

Azure CLI
az account show

image.png
⑤接続しているサブスクリプションを変更する場合は、下記のコマンドを入力
(今回はMS-Learnのサンドボックスに変更)

Azure CLI
az account set --name "Concierge Subscription"

※コマンドの意味
・az account set --name サブスクリプション名
指定したサブスクリプション名のサブスクリプションに接続先を変更
(--subscriptionでID指定することも可能)

リソースグループの確認と作成

⑥Azure CLI上で「az group list」を入力し、接続しているサブスクリプションのリソースグループをすべて表示

Azure CLI
az group list --output table

image.png
※コマンドの意味
・--output table(省略:-o table)
出力を表形式にするグローバルパラメーター(省略可能)
 -グローバルパラメーター:他のコマンドでも使用可能なパラメーター

例)output tableを使用しない場合の出力
image.png

⑦リソースグループを作成する場合はAzure CLI上で下記を入力
(サンドボックスを使用している場合は作成できないため省略)

Azure CLI
az group create --name "[リソースグループ名]" --location "[リージョン]"

⑧リソースグループ名を変数として登録しておきたい場合は、Azure CLI上で下記を入力

Azure CLI
export RSGroup="[ResourceGroup名]"

※コマンドの意味
・export 変数名=格納したい値
変数を作成可能
 -作成した変数を使用したい場合は「$変数名」で使用可能

リソースの作成

⑨Azure CLI上で下記のコマンドを入力し、仮想マシンを作成

Azure CLI
az vm create \
 --name "testvm-eus-01" \
 --resource-group $RSGroup \
 --admin-username "[ログイン用ユーザ名]" \
 --admin-password "[ログイン用パスワード]" \
 --location "East US" \
 --image UbuntuLTS \
 --public-ip-address "testvm-01"

※コマンドの意味
・az vm create
仮想マシン(VM)を作成するコマンド
・「\」
入力中に改行させるためのコマンド(省略する場合はすべて一行で記述)
・name
リソース名を指定
・resource-group
VMを作成するリソースグループを指定
・admin-username
VMのユーザ名(デフォルトはOSの現在のユーザ名)を指定
・admin-password
パスワード認証の場合のVMのパスワードを指定
・location
VMを作成するリージョンを指定
・image
VMに使用するOSを指定
・public-ip-address
VMが使うパブリックIPアドレスの名前を指定

作成したリソースの確認

⑩Azure CLI上で下記を入力し、作成したVMを表示

Azure CLI
az vm list -g $RSGroup -d -o table

image.png
※コマンドの意味
・--resource-group(省略:-g)
表示させるVMのリソースグループを指定可能
・--show-details(省略:-d)
パブリックIPアドレスやFQDN、電源状態も表示

次の学習内容

◆AzureへのARMテンプレートのデプロイ

学習内容をまとめたページの一覧

3
0
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
3
0