3 CostInformation - Azure/AzRegionSelection GitHub Wiki
3-CostInformation
Cost data retrieval and region comparison
Get-CostInformation.ps1
This script is intended to take a collection of given resource IDs and return the cost incurred during previous months, grouped as needed. For this we use the Microsoft.CostManagement provider of each subscription. This means one call of the Cost Management PowerShell module per subscription.
The input file is produced by the Get-AzureServices.ps1 script.
Requires Az.CostManagement module version 0.4.2.
PS1> Install-Module -Name Az.CostManagement
Instructions for use:
- Log on to Azure using
Connect-AzAccount. Ensure that you have Cost Management Reader access to each subscription listed in the resources file (defaultresources.json) - Navigate to the 3-CostInformation folder and run the script using
.\Get-CostInformation.ps1. The script will generate a CSV file in the current folder.
Documentation links - cost retrieval
Documentation regarding the Az.CostManagement module is not always straightforward. Helpful links are:
| Documentation | Link |
|---|---|
| Cost Management Query (API) | Link |
| Az.CostManagement Query (PowerShell) | Link |
Valid dimensions for grouping are:
AccountName
BenefitId
BenefitName
BillingAccountId
BillingMonth
BillingPeriod
ChargeType
ConsumedService
CostAllocationRuleName
DepartmentName
EnrollmentAccountName
Frequency
InvoiceNumber
MarkupRuleName
Meter
MeterCategory
MeterId
MeterSubcategory
PartNumber
PricingModel
PublisherType
ReservationId
ReservationName
ResourceGroup
ResourceGroupName
ResourceGuid
ResourceId
ResourceLocation
ResourceType
ServiceName
ServiceTier
SubscriptionId
SubscriptionName
Perform-RegionComparison.ps1
This script builds on the collection step by comparing pricing across Azure regions for the meter ID's retrieved earlier. The Azure public pricing API is used, meaning that:
- No login is needed for this step
- Prices are not customer-specific, but are only used to calculate the relative cost difference between regions for each meter
As customer discounts tend to be linear (for example, ACD is a flat rate discount across all PAYG Azure spend), the relative price difference between regions can still be used to make an intelligent estimate of the cost impact of a workload move.
Instructions for use:
- Prepare a list of target regions for comparison. This can be provided at the command line or stored in a variable before calling the script.
- Ensure the
resources.jsonfile is present (from the running of the collector script). - Run the script using
.\Perform-RegionComparison.ps1. The script will generate output files in the current folder.
Example
$regions = @("eastus", "brazilsouth", "australiaeast")
.\Perform-RegionComparison.ps1 -regions $regions -outputType json
Outputs
Depending on the chosen output format, the script outputs four sets of data:
| Dataset | Contents |
|---|---|
inputs |
The input data used for calling the pricing API (for reference only) |
pricemap |
An overview of which regions are cheaper / similarly-priced / more expensive for each meter ID |
prices |
Prices for each source/target region mapping by meter ID |
uomerrors |
A list of any eventual mismatches of Unit Of Measure between regions |
Documentation links - region comparison
| Documentation | Link |
|---|---|
| Azure pricing API | Link |