【 Cloud 】透過 Logic App 定時啟動 Azure VM
內容
- 學習目標
- 前置準備作業
- 建立與設定 Logic App
- 設定 Azure VM
- 測試與驗證
學習目標
- 如何透過
Logic App定時啟動Azure VM
前置準備作業
- 已建立 Azure 帳號並能正常登入
- 已於 Azure 建立 Virtual machine
建立與設定 Logic App
Step 1. 開啟 Logic App
- 在上方搜尋框輸入
logic並點選下方Logic Apps的搜尋結果

Step 2. 建立 Logic Apps
- 點選左上角的
+ Create

Step 3. 輸入相關資訊

Subscription欄位請選擇所要使用哪個訂閱帳號Resource Group欄位請選擇使用舊有的或新建立一個新的Type欄位請選擇ConsumptionLogic App name欄位請輸入一個唯一且可識別的名稱- 本範例使用
boot-logic-app
- 本範例使用
Region欄位請選擇此服務所要建立在哪個資料中心- 以上資訊輸入完成後請點選左下角的
Review + create

Step 4. 再次確認相關資訊後請按左下角的 Create

Step 5. 建立完成畫面並點選 Go to resource

Step 6. 點選 Recurrence

Step 7. 設定 Recurrence
- 本範例預計
每日早上 8:30自動開啟 Azure VM

Interval欄位請輸入1Frequency欄位請輸入Day- 點選
Add new parameter中的Time zone、At these hours、At these minutes


- 設定時區與時間
Time zone欄位請選擇所在的時間- 本範例為
(UTC+08:00) Taipei
- 本範例為
At these hours欄位請選擇8At these minutes欄位請輸入30


Step 8. 設定啟動 Azure VM Logic
- 點選
+ New step

- 點選
HTTP

- 輸入相關資訊
Method欄位請選擇POSTURI欄位請輸入下方 URI 並修改其中的Subscription-ID、Resource-Group、Computer-Name為 Azure VM 所對應的屬性
https://management.azure.com/subscriptions/Subscription-ID/resourceGroups/Resource-Group/providers/Microsoft.Compute/virtualMachines/Computer-Name/start?api-version=2019-12-01
- 點選
Add new parameter
- 選擇
Authentication

Authentication type欄位選擇Managed identity



- 選擇
- 以上資訊輸入完成後點選
Save

Step 9. 啟用 Logic App Identity
- 回到所建立的 Logic App 頁點再點選左側的
Identity> 再點選On> 點選Save

- 點選
Yes

設定 Azure VM
Step 1. 回到所建立的 Azure VM 並把 VM 關機

Step 2. 點選左側的 Access control (IAM)

Step 3. 點選 + Add

Step 4. 點選 Add role assignment

Step 5. 點選 Virtual Machine Contributor 後再點選 Next

Step 6. 設定 Member 資訊

- 輸入相關資訊
Assign access to欄位點選Managed identity

Members點選+ Select members再點選所建立的 Logic App 後點選Select

- 以上資訊輸入完成後請點選左下角的
Review + assign

- 再次確認資訊後請點選左下角的
Review + assign

測試與驗證
Step 1. 回到所建立的 Logic App

Step 2. 點選上方的 Run Trigger

Step 3. 點選 Run

Step 4. Trigger 結果
- Trigger Running

- Trigger Success

- 此時 Azure VM 已開機完成
