Share via


Quickstart: Een budget maken met Bicep

Met budgetten in Cost Management kunt u de verantwoordelijkheid in de organisatie beter plannen en stimuleren. Met budgetten kunt u de Azure-services die u gebruikt of waarop u zich abonneert voor een specifieke periode bijhouden. Ze helpen u anderen te informeren over hun uitgaven om kosten proactief te beheren en de voortgang van de uitgaven in de loop van de tijd te controleren. Wanneer de budgetdrempels die u hebt gemaakt, worden overschreden, worden er meldingen geactiveerd. Dit heeft geen gevolgen voor uw resources en uw gebruik wordt niet gestopt. U kunt budgetten gebruiken om bestedingen te vergelijken en bij te houden bij het analyseren van kosten. In deze quickstart ziet u hoe u een budget met de naam 'MyBudget' maakt met bicep.

Bicep is een domeinspecifieke taal (DSL) die declaratieve syntaxis gebruikt om Azure-resources te implementeren. Het biedt beknopte syntaxis, betrouwbare typeveiligheid en ondersteuning voor het hergebruik van code. Bicep biedt de beste ontwerpervaring voor uw infrastructuur-als-code-oplossingen in Azure.

Vereisten

Als u nog geen abonnement op Azure hebt, maak dan een gratis account aan voordat u begint.

Als u een nieuw abonnement hebt, kunt u niet direct een budget maken of andere Cost Management-functies gebruiken. Het kan tot 48 uur duren voordat u alle Cost Management-functies kunt gebruiken.

Budgetten worden ondersteund voor de volgende Azure-accounttypen en -bereiken:

  • Azure RBAC-bereiken (op rollen gebaseerd toegangsbeheer)
    • Beheergroepen
    • Abonnement
  • Enterprise Agreement-bereiken
    • Factureringsaccount
    • Afdeling
    • Inschrijvingsaccount
  • Afzonderlijke overeenkomsten
    • Factureringsaccount
  • Microsoft-klantovereenkomst-bereiken
    • Factureringsaccount
    • Factureringsprofiel
    • Factuursectie
    • Klant
  • AWS-bereiken
    • Extern account
    • Extern abonnement

Als u budgetten wilt weergeven, hebt u minimaal leestoegang voor uw Azure-account nodig.

Voor Azure EA-abonnementen moet u leestoegang hebben om budgetten weer te geven. Als u budgetten wilt maken en beheren, moet u de machtiging Inzender hebben.

In abonnementen worden de volgende Azure-machtigingen, of bereiken, ondersteund voor budgetten voor gebruikers en groepen. Zie Understand and work with scopes (Engelstalig) voor meer informatie over bereiken.

  • Eigenaar: eigenaren kunnen budgetten voor een abonnement maken, wijzigen en verwijderen.
  • Inzender en Inzender Cost Management: inzenders kunnen hun eigen budgetten maken, wijzigen en verwijderen. Inzenders kunnen ook de budgetbedragen aanpassen voor budgetten die zijn gemaakt door anderen.
  • Lezer en Lezer Cost Management: lezers kunnen budgetten inzien waarvoor ze zijn gemachtigd.

Zie Toegang tot gegevens van Cost Management toewijzen voor meer informatie over het toewijzen van toegang tot de gegevens van Cost Management.

Geen filter

Het Bicep-bestand controleren

Het Bicep-bestand dat in deze quickstart wordt gebruikt, is afkomstig uit Azure-snelstartsjablonen.

targetScope = 'subscription'

@description('Name of the Budget. It should be unique within a resource group.')
param budgetName string = 'MyBudget'

@description('The total amount of cost or usage to track with the budget')
param amount int = 1000

@description('The time covered by a budget. Tracking of the amount will be reset based on the time grain.')
@allowed([
  'Monthly'
  'Quarterly'
  'Annually'
])
param timeGrain string = 'Monthly'

@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.')
param startDate string

@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.')
param endDate string

@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.')
param firstThreshold int = 90

@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.')
param secondThreshold int = 110

@description('The list of email addresses to send the budget notification to when the threshold is exceeded.')
param contactEmails array

resource budget 'Microsoft.Consumption/budgets@2023-11-01' = {
  name: budgetName
  properties: {
    timePeriod: {
      startDate: startDate
      endDate: endDate
    }
    timeGrain: timeGrain
    amount: amount
    category: 'Cost'
    notifications: {
      NotificationForExceededBudget1: {
        enabled: true
        operator: 'GreaterThan'
        threshold: firstThreshold
        contactEmails: contactEmails
      }
      NotificationForExceededBudget2: {
        enabled: true
        operator: 'GreaterThan'
        threshold: secondThreshold
        contactEmails: contactEmails
      }
    }
  }
}

output name string = budget.name
output resourceId string = budget.id

Er is één Azure-resource gedefinieerd in het Bicep-bestand:

Het Bicep-bestand implementeren

  1. Sla het Bicep-bestand op als main.bicep op uw lokale computer.

  2. Implementeer het Bicep-bestand met behulp van Azure CLI of Azure PowerShell.

    myContactEmails ='("user1@contoso.com", "user2@contoso.com")'
    
    az deployment sub create --name demoSubDeployment --location centralus --template-file main.bicep --parameters startDate=<start-date> endDate=<end-date> contactEmails=$myContactEmails
    

    U moet de volgende parameters invoeren:

    • startDate: vervang begindatum> door< de begindatum. Dit moet de eerste van de maand zijn in de indeling JJJJ-MM-DD. Een toekomstige begindatum mag niet langer zijn dan drie maanden in de toekomst. Binnen de periode van de tijdsperiode moet een begindatum worden geselecteerd.
    • endDate: vervang de einddatum> door< de einddatum in de notatie JJJJ-MM-DD. Als deze niet wordt opgegeven, wordt de standaardinstelling tien jaar vanaf de begindatum.
    • contactEmails: maak eerst een variabele die uw e-mailberichten bevat en geef die variabele vervolgens door. Vervang de voorbeeld-e-mailberichten door de e-mailadressen waarnaar u de budgetmelding wilt verzenden wanneer de drempelwaarde wordt overschreden.

    Notitie

    Wanneer de implementatie is voltooid, ziet u een bericht dat aangeeft dat de implementatie is voltooid.

Eén filter

Het Bicep-bestand controleren

Het Bicep-bestand dat in deze quickstart wordt gebruikt, is afkomstig uit Azure-snelstartsjablonen.

targetScope = 'subscription'

@description('Name of the Budget. It should be unique within a resource group.')
param budgetName string = 'MyBudget'

@description('The total amount of cost or usage to track with the budget')
param amount int = 1000

@description('The time covered by a budget. Tracking of the amount will be reset based on the time grain.')
@allowed([
  'Monthly'
  'Quarterly'
  'Annually'
])
param timeGrain string = 'Monthly'

@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.')
param startDate string

@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.')
param endDate string

@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.')
param firstThreshold int = 90

@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.')
param secondThreshold int = 110

@description('The list of email addresses to send the budget notification to when the threshold is exceeded.')
param contactEmails array

@description('The set of values for the resource group filter.')
param resourceGroupFilterValues array

resource budget 'Microsoft.Consumption/budgets@2021-10-01' = {
  name: budgetName
  properties: {
    timePeriod: {
      startDate: startDate
      endDate: endDate
    }
    timeGrain: timeGrain
    amount: amount
    category: 'Cost'
    notifications: {
      NotificationForExceededBudget1: {
        enabled: true
        operator: 'GreaterThan'
        threshold: firstThreshold
        contactEmails: contactEmails
      }
      NotificationForExceededBudget2: {
        enabled: true
        operator: 'GreaterThan'
        threshold: secondThreshold
        contactEmails: contactEmails
      }
    }
    filter: {
      dimensions: {
        name: 'ResourceGroupName'
        operator: 'In'
        values: resourceGroupFilterValues
      }
    }
  }
}

Er is één Azure-resource gedefinieerd in het Bicep-bestand:

Het Bicep-bestand implementeren

  1. Sla het Bicep-bestand op als main.bicep op uw lokale computer.

  2. Implementeer het Bicep-bestand met behulp van Azure CLI of Azure PowerShell.

    myContactEmails ='("user1@contoso.com", "user2@contoso.com")'
    myRgFilterValues ='("resource-group-01", "resource-group-02")'
    
    az deployment sub create --name demoSubDeployment --location centralus --template-file main.bicep --parameters startDate=<start-date> endDate=<end-date> contactEmails=$myContactEmails resourceGroupFilterValues=$myRgFilterValues
    

    U moet de volgende parameters invoeren:

    • startDate: vervang begindatum> door< de begindatum. Dit moet de eerste van de maand zijn in de indeling JJJJ-MM-DD. Een toekomstige begindatum mag niet langer zijn dan drie maanden in de toekomst. Binnen de periode van de tijdsperiode moet een begindatum worden geselecteerd.
    • endDate: vervang de einddatum> door< de einddatum in de notatie JJJJ-MM-DD. Als deze niet wordt opgegeven, wordt de standaardinstelling tien jaar vanaf de begindatum.
    • contactEmails: maak eerst een variabele die uw e-mailberichten bevat en geef die variabele vervolgens door. Vervang de voorbeeld-e-mailberichten door de e-mailadressen waarnaar u de budgetmelding wilt verzenden wanneer de drempelwaarde wordt overschreden.
    • resourceGroupFilterValues Maak eerst een variabele die de filterwaarden van uw resourcegroep bevat en geef die variabele vervolgens door. Vervang de voorbeeldfilterwaarden door de set waarden voor uw resourcegroepfilter.

    Notitie

    Wanneer de implementatie is voltooid, ziet u een bericht dat aangeeft dat de implementatie is voltooid.

Twee of meer filters

Het Bicep-bestand controleren

Het Bicep-bestand dat in deze quickstart wordt gebruikt, is afkomstig uit Azure-snelstartsjablonen.

targetScope = 'subscription'

@description('Name of the Budget. It should be unique within a resource group.')
param budgetName string = 'MyBudget'

@description('The total amount of cost or usage to track with the budget')
param amount int = 1000

@description('The time covered by a budget. Tracking of the amount will be reset based on the time grain.')
@allowed([
  'Monthly'
  'Quarterly'
  'Annually'
])
param timeGrain string = 'Monthly'

@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.')
param startDate string

@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.')
param endDate string

@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.')
param firstThreshold int = 90

@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.')
param secondThreshold int = 110

@description('The list of contact roles to send the budget notification to when the threshold is exceeded.')
param contactRoles array = [
  'Owner'
  'Contributor'
  'Reader'
]

@description('The list of email addresses to send the budget notification to when the threshold is exceeded.')
param contactEmails array

@description('The list of action groups to send the budget notification to when the threshold is exceeded. It accepts array of strings.')
param contactGroups array

@description('The set of values for the resource group filter.')
param resourceGroupFilterValues array

@description('The set of values for the meter category filter.')
param meterCategoryFilterValues array

resource budget 'Microsoft.Consumption/budgets@2021-10-01' = {
  name: budgetName
  properties: {
    timePeriod: {
      startDate: startDate
      endDate: endDate
    }
    timeGrain: timeGrain
    amount: amount
    category: 'Cost'
    notifications: {
      NotificationForExceededBudget1: {
        enabled: true
        operator: 'GreaterThan'
        threshold: firstThreshold
        contactEmails: contactEmails
        contactRoles: contactRoles
        contactGroups: contactGroups
      }
      NotificationForExceededBudget2: {
        enabled: true
        operator: 'GreaterThan'
        threshold: secondThreshold
        contactEmails: contactEmails
        contactRoles: contactRoles
        contactGroups: contactGroups
        thresholdType: 'Forecasted'
      }
    }
    filter: {
      and: [
        {
          dimensions: {
            name: 'ResourceGroupName'
            operator: 'In'
            values: resourceGroupFilterValues
          }
        }
        {
          dimensions: {
            name: 'MeterCategory'
            operator: 'In'
            values: meterCategoryFilterValues
          }
        }
      ]
    }
  }
}

Er is één Azure-resource gedefinieerd in het Bicep-bestand:

Het Bicep-bestand implementeren

  1. Sla het Bicep-bestand op als main.bicep op uw lokale computer.

  2. Implementeer het Bicep-bestand met behulp van Azure CLI of Azure PowerShell.

    myContactEmails ='("user1@contoso.com", "user2@contoso.com")'
    myContactGroups ='("/subscriptions/{sub-id}/resourceGroups/{rg-name}/providers/microsoft.insights/actionGroups/groupone", "/subscriptions/{sub-id}/resourceGroups/{rg-name}/providers/microsoft.insights/actionGroups/grouptwo")'
    myRgFilterValues ='("resource-group-01", "resource-group-02")'
    myMeterCategoryFilterValues ='("meter-category-01", "meter-category-02")'
    
    az deployment sub create --name demoSubDeployment --location centralus --template-file main.bicep --parameters startDate=<start-date> endDate=<end-date> contactEmails=$myContactEmails contactGroups=$myContactGroups resourceGroupFilterValues=$myRgFilterValues meterCategoryFilterValues=$myMeterCategoryFilterValues
    

    U moet de volgende parameters invoeren:

    • startDate: vervang begindatum> door< de begindatum. Dit moet de eerste van de maand zijn in de indeling JJJJ-MM-DD. Een toekomstige begindatum mag niet langer zijn dan drie maanden in de toekomst. Binnen de periode van de tijdsperiode moet een begindatum worden geselecteerd.
    • endDate: vervang de einddatum> door< de einddatum in de notatie JJJJ-MM-DD. Als deze niet wordt opgegeven, wordt de standaardinstelling tien jaar vanaf de begindatum.
    • contactEmails: maak eerst een variabele die uw e-mailberichten bevat en geef die variabele vervolgens door. Vervang de voorbeeld-e-mailberichten door de e-mailadressen waarnaar u de budgetmelding wilt verzenden wanneer de drempelwaarde wordt overschreden.
    • contactGroups: maak eerst een variabele die uw groepen contactpersonen bevat en geef die variabele vervolgens door. Vervang de voorbeeldgroepen met contactpersonen door de lijst met actiegroepen waar de budgetmelding naartoe moet worden verzonden wanneer de drempelwaarde wordt overschreden. U moet de resource-id van de actiegroep doorgeven, die u kunt ophalen met az monitor action-group show of Get-AzActionGroup.
    • resourceGroupFilterValues: maak eerst een variabele die de filterwaarden van uw resourcegroep bevat en geef die variabele vervolgens door. Vervang de voorbeeldfilterwaarden door de set waarden voor uw resourcegroepfilter.
    • meterCategoryFilterValues: maak eerst een variabele die de filterwaarden voor uw metercategorie bevat en geef die variabele vervolgens door. Vervang de voorbeeldfilterwaarden tussen haakjes door de set waarden voor uw metercategoriefilter.

    Notitie

    Wanneer de implementatie is voltooid, ziet u een bericht dat aangeeft dat de implementatie is voltooid.

Geïmplementeerde resources bekijken

Gebruik de Azure Portal, Azure CLI of Azure PowerShell om de geïmplementeerde resources in de resourcegroep weer te geven.

az consumption budget list

Resources opschonen

Wanneer u het budget niet meer nodig hebt, gebruikt u de Azure Portal, Azure CLI of Azure PowerShell om het te verwijderen:

az consumption budget delete --budget-name MyBudget

Volgende stappen

In deze quickstart hebt u een budget gemaakt en dit budget geïmplementeerd met bicep. Ga verder met de onderstaande artikelen voor meer informatie over Cost Management en Facturering en Bicep.