仮想マシン>オートメーション>タスク について

cinq81 195 評価のポイント
2025-09-18T07:14:56.03+00:00

オートメーションテンプレート「Deallocate Virtual Machine」で、VMの割り当て解除を実行できますが、VMが起動しているときに割り当て解除を行いたくありません。

VMのStatusが"VM stopped"の時にだけ、VMの割り当て解除を実行する方法はありますでしょうか。

Azure Logic Apps
Azure Logic Apps

コードを記述せずにクラウド間でのデータのアクセスと使用を自動化する Azure サービス。


質問作成者が受け入れた回答
Rakesh Mishra 11,350 評価のポイント Microsoft 外部スタッフ モデレーター
2025-09-18T11:12:33.16+00:00

こんにちは cinq81,

Microsoft Q&A プラットフォームへようこそ! ここにご質問をいただきありがとうございます。

Logic App で「仮想マシンの割り当て解除(Deallocate Virtual Machine)」アクションを実行する前に追加すべき手順は以下のとおりです。

  1. HTTP – instanceView の取得
    • 新しいアクションを追加 → HTTP コネクタ を検索 → HTTP を選択。
    • Method = GET を設定。
    • URI には、サブスクリプション ID・リソース グループ・VM 名を置き換えるか、Logic App パラメータにすでに設定されている値を使用。
    • VM InstanceView エンドポイント:
           https://management.azure.com/subscriptions/<SUB_ID>/resourceGroups/<RG>/providers/Microsoft.Compute/virtualMachines/<VM_NAME>/instanceView?api-version=2024-11-01
    
    • Authentication では Managed Identity を選択し、System-assigned managed identity を指定。
    • セーブ。
  2. JSON の解析 – instanceView
    • 新しいアクションを追加 → Parse JSON を検索。
    • Content に HTTP アクションの Body を指定。
    • Use sample payload to generate schema をクリック → InstanceView のサンプルレスポンスを貼り付け。
    • サンプルスキーマ:
       {
         "type": "object",
         "properties": {
           "disks": { "type": "array" },
           "bootDiagnostics": { "type": "object" },
           "hyperVGeneration": { "type": "string" },
           "statuses": {
             "type": "array",
             "items": {
               "type": "object",
               "properties": {
                 "code": { "type": "string" },
                 "level": { "type": "string" },
                 "displayStatus": { "type": "string" },
                 "time": { "type": "string" }
               }
             }
           }
         }
       }
    
    • セーブ。
  3. フィルター配列 – PowerState
    • 新しいアクションを追加 → Filter array を検索。
    • From には Parse JSON 出力の statuses を指定。
    • 条件付き式:
      • 左:コード
      • 演算子: contains
      • 右: PowerState
    • セーブ
  4. 変数を設定する – PowerStateCode
    • Logic App の最初に Initialize variable アクションを追加:
      • 名前: PowerStateCode
      • タイプ: 文字列
      • Value: 空のまま
    • Filter array の後に Set variable アクションを追加。
    • 変数 PowerStateCode を選択。
    • Value に Filter array 出力の最初の code フィールドを指定。
      • (動的コンテンツ→ Filter array のコード)
    • これにより、変数がループ内で設定される。
  5. 状態 – IsStoppedOrDeallocated?
    • Condition アクションを追加。
    • 左: 変数 PowerStateCode
    • 演算子:は
    • 右: PowerState/stopped
      • Add row をクリック →再度 PowerStateCode、演算子 is equal to、値 PowerState/deallocated を追加。
    • 条件ロジックを Or に変更(stopped または deallocated のいずれかに一致)。
    • セーブ。
  6. 結果:
    • True の場合: 「Deallocate Virtual Machine」アクションを追加。
    • False の場合: ログ用アクション(例: Compose に「Skipping deallocate, VM is running」と記録)を追加。

この回答は役に立ちましたか?


0 件の追加の回答

並べ替え方法: 最も役に立つ

お客様の回答

質問作成者は回答に "承認済み"、モデレーターは "推奨" とマークできます。これにより、ユーザーは作成者の問題が回答によって解決したことを把握できます。