快速入門:使用ARM範本建立預算

成本管理中的預算可協助您進行規劃並促進組織責任歸屬。 透過預算,您可以考慮您在特定期間取用或訂閱的 Azure 服務。 它們可協助您通知其他人其費用的相關資訊以主動管理成本,並監視費用在經過一段時間的進展方式。 超過您建立的預算閾值時,會觸發通知。 您的資源都會不受到影響,而您的使用量並不會停止。 當您分析成本時,您可以使用預算來比較及追蹤費用。 本快速入門說明如何使用三個不同的 Azure Resource Manager 範本建立預算(ARM 範本)。

Azure Resource Manager 範本是 JavaScript 物件表示法 (JSON) 檔案,可定義專案的基礎結構和組態。 範本使用宣告式語法。 您不需要撰寫程式設計命令順序來建立部署,即可描述預定的部署。

如果您的環境符合必要條件,且您已熟悉使用ARM範本,請選取 下列其中一個範本的 [部署至 Azure ] 按鈕。 範本會在 Azure 入口網站中開啟。

範本 [部署] 按鈕
沒有篩選 將 Resource Manager 範本部署至 Azure 的按鈕。
一個篩選 將 Resource Manager 範本部署至 Azure 的按鈕。
兩個或多個篩選 將 Resource Manager 範本部署至 Azure 的按鈕。

必要條件

如果您沒有 Azure 訂用帳戶,請在開始前建立免費帳戶

如果您有新的訂用帳戶,就無法立即建立預算或使用成本管理功能。 最多可能需要 48 小時的時間,才能使用所有的成本管理功能。

預算受下列類型的 Azure 帳戶類型和範圍支援:

  • Azure 角色型訪問控制 (Azure RBAC) 範圍
    • 管理群組
    • 訂用帳戶
  • Enterprise 合約 範圍
    • 計費帳戶
    • department
    • 註冊帳戶
  • 個別合約
    • 計費帳戶
  • Microsoft 客戶合約 範圍
    • 計費帳戶
    • 帳單設定檔
    • 發票區段
    • 客戶
  • AWS 範圍
    • 外部帳戶
    • 外部訂用帳戶

      注意

      成本管理服務中 AWS 的 連線 者將於 2025 年 3 月 31 日淘汰。 用戶應該考慮 AWS 成本管理報告的替代解決方案。 在 2024 年 3 月 31 日,Azure 會停用為所有客戶新增 AWS 連線 ors 的能力。 如需詳細資訊,請參閱 淘汰 Amazon Web Services (AWS) 連接器。 若要檢視預算,您至少需要 Azure 帳戶的讀取存取。

針對 Azure EA 訂用帳戶,您必須具備檢視預算的讀取存取權。 若要建立及管理預算,您必須具有參與者權限。

使用者和群組針對預算的每個訂用帳戶支援下列 Azure 權限或範圍。 如需有關範圍的詳細資訊,請參閱了解並使用範圍

  • 擁有者:可以建立、修改或刪除訂用帳戶的預算。
  • 參與者和成本管理參與者:可以建立、修改或刪除他們自己的預算。 可以修改其他人所建立之預算的預算金額。
  • 讀者和成本管理讀者:可以檢視他們有權限的預算。

如需將許可權指派給成本管理數據的詳細資訊,請參閱 指派成本管理數據的存取權。

根據您的需求,使用下列其中一個範本。

範本 描述
沒有篩選 ARM 樣本沒有任何篩選。
一個篩選 ARM 樣本具有資源群組的篩選條件。
兩個或多個篩選 ARM 樣本具有資源群組的篩選,以及計量類別的篩選。

檢閱及部署範本

檢閱範本

本快速入門中使用的範本是來自 Azure 快速入門範本

{
  "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.26.54.24096",
      "templateHash": "10216192224502761212"
    }
  },
  "parameters": {
    "budgetName": {
      "type": "string",
      "defaultValue": "MyBudget",
      "metadata": {
        "description": "Name of the Budget. It should be unique within a resource group."
      }
    },
    "amount": {
      "type": "int",
      "defaultValue": 1000,
      "metadata": {
        "description": "The total amount of cost or usage to track with the budget"
      }
    },
    "timeGrain": {
      "type": "string",
      "defaultValue": "Monthly",
      "allowedValues": [
        "Monthly",
        "Quarterly",
        "Annually"
      ],
      "metadata": {
        "description": "The time covered by a budget. Tracking of the amount will be reset based on the time grain."
      }
    },
    "startDate": {
      "type": "string",
      "metadata": {
        "description": "The start date must be first of the month in YYYY-MM-DD format. Future start date should not be more than three months. Past start date should be selected within the timegrain preiod."
      }
    },
    "endDate": {
      "type": "string",
      "metadata": {
        "description": "The end date for the budget in YYYY-MM-DD format. If not provided, we default this to 10 years from the start date."
      }
    },
    "firstThreshold": {
      "type": "int",
      "defaultValue": 90,
      "metadata": {
        "description": "Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0.01 and 1000."
      }
    },
    "secondThreshold": {
      "type": "int",
      "defaultValue": 110,
      "metadata": {
        "description": "Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0.01 and 1000."
      }
    },
    "contactEmails": {
      "type": "array",
      "metadata": {
        "description": "The list of email addresses to send the budget notification to when the threshold is exceeded."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Consumption/budgets",
      "apiVersion": "2023-11-01",
      "name": "[parameters('budgetName')]",
      "properties": {
        "timePeriod": {
          "startDate": "[parameters('startDate')]",
          "endDate": "[parameters('endDate')]"
        },
        "timeGrain": "[parameters('timeGrain')]",
        "amount": "[parameters('amount')]",
        "category": "Cost",
        "notifications": {
          "NotificationForExceededBudget1": {
            "enabled": true,
            "operator": "GreaterThan",
            "threshold": "[parameters('firstThreshold')]",
            "contactEmails": "[parameters('contactEmails')]"
          },
          "NotificationForExceededBudget2": {
            "enabled": true,
            "operator": "GreaterThan",
            "threshold": "[parameters('secondThreshold')]",
            "contactEmails": "[parameters('contactEmails')]"
          }
        }
      }
    }
  ],
  "outputs": {
    "name": {
      "type": "string",
      "value": "[parameters('budgetName')]"
    },
    "resourceId": {
      "type": "string",
      "value": "[subscriptionResourceId('Microsoft.Consumption/budgets', parameters('budgetName'))]"
    }
  }
}

此範本中已定義一項 Azure 資源:

部署範本

  1. 選取以下影像來登入 Azure 並開啟範本。 範本會建立預算,而沒有任何篩選條件。

    將 Resource Manager 範本部署至 Azure 的按鈕。

  2. 選取或輸入下列值。

    Resource Manager 範本:建立預算而不需篩選、部署入口網站。

    • 訂用帳戶:選取 Azure 訂用帳戶。
    • 資源群組:如有需要,請選取現有的資源群組,或 [新建]。
    • 區域:選取 Azure 區域。 例如,美國中部
    • 預算名稱:輸入預算的名稱。 資源群組內應該是唯一的。 只允許英數位元、底線和連字元字元。
    • 金額:輸入與預算一起追蹤的成本總計。
    • 時間粒紋:輸入預算涵蓋的時間。 允許的值為每月、每季或每年。 預算會在時間粒紋結束時重設。
    • 開始日期:以YYYY-MM-DD格式輸入月份第一天的開始日期。 從今天起,未來的開始日期不應該超過三個月。 您可以使用時間粒紋期間來指定過去的開始日期。
    • 結束日期:以YYYY-MM-DD格式輸入預算的結束日期。
    • 第一個閾值:輸入第一個通知的臨界值。 當成本超過閾值時,就會傳送通知。 一律為百分比,且必須介於 0.01 到 1000 之間。
    • 第二個臨界值:輸入第二個通知的臨界值。 當成本超過閾值時,就會傳送通知。 一律為百分比,且必須介於 0.01 到 1000 之間。
    • 聯繫人電子郵件 輸入電子郵件地址清單,以在超過閾值時傳送預算通知。 它會接受字串陣列。 預期的格式為 ["user1@domain.com","user2@domain.com"]
  3. 根據您的 Azure 訂用帳戶類型,執行下列其中一個動作:

    • 選取 [檢閱 + 建立]。
    • 檢閱條款及條件,選取 [ 我同意上述條款及條件],然後選取 [ 購買]。
  4. 如果您選取 [ 檢閱 + 建立],則會驗證您的範本。 選取 建立

    顯示 Resource Manager 範本、預算沒有篩選、部署入口網站通知的螢幕快照。

Azure 入口網站用於部署範本。 除了 Azure 入口網站,您也可以使用 Azure PowerShell、Azure CLI 和 REST API。 若要瞭解其他部署範本,請參閱 部署範本

驗證部署

使用下列其中一種方式來確認已建立預算。

流覽至 [成本管理 + 計費>] 選取 [預算] 範圍>

清除資源

當您不再需要預算時,請使用下列其中一種方法加以刪除:

流覽至 [成本管理 + 計費>] 選取計費範圍> [預算>] 選取預算>,然後選取 [刪除預算]。

下一步

在本快速入門中,您已建立預算並加以部署。 若要深入瞭解成本管理和計費和 Azure Resource Manager,請繼續閱讀下列文章。