Fix Azure pricesheet billing period fetch for MCA accounts#1
Draft
Fix Azure pricesheet billing period fetch for MCA accounts#1
Conversation
Co-authored-by: DonadoJuan <13824533+DonadoJuan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix billing period format for MCA accounts
Fix Azure pricesheet billing period fetch for MCA accounts
Feb 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The hardcoded
yyyyMMbilling period format ingetDownloadURLonly works for EA accounts. MCA accounts useyyyyMM-1(e.g.,202411-1), causing the Azure API to return a 404 for those users.Changes
pricesheetclient.go: AddGetCurrentBillingPeriodmethod that calls the Azure Billing Periods List API (/providers/Microsoft.Billing/billingAccounts/{id}/billingPeriods?$top=1) to retrieve the most recent billing period name, handling both EA and MCA name formats dynamically.pricesheetdownloader.go: UpdategetDownloadURLto callGetCurrentBillingPeriodinstead of the hardcoded formatter. Falls back to the originalyyyyMMformat if the API call fails, preserving backward compatibility.pricesheetclient_test.go: Add validation test forGetCurrentBillingPeriodwith empty billing account ID.Original prompt
Problem
GitHub Issue: opencost#2996
The
currentBillingPeriod()function inpkg/cloud/azure/pricesheetdownloader.go(line 263) hardcodes the billing period format asyyyyMM(e.g.,202411):This works for Enterprise Agreement (EA) billing accounts, but Microsoft Customer Agreement (MCA) billing accounts use billing period names with a different format:
yyyyMM-1(e.g.,202411-1). When the hardcodedyyyyMMformat is used against an MCA billing account, the Azure API returns:The user confirmed that their billing periods (listed via
az billing period list) are formatted as202502-1,202501-1,202412-1, etc.Required Fix
Modify
getDownloadURLinpkg/cloud/azure/pricesheetdownloader.goto dynamically fetch the current billing period name from the Azure Billing Periods List API instead of using a hardcoded format. Here is the approach:1. Add a
GetCurrentBillingPeriodmethod toPriceSheetClientinpkg/cloud/azure/pricesheetclient.goAdd these new types and the method after the existing
downloadByBillingPeriodCreateRequestfunction:You will also need to add
"encoding/json"and"io"to the imports inpricesheetclient.go.2. Update
getDownloadURLinpkg/cloud/azure/pricesheetdownloader.goReplace the existing
getDownloadURLmethod (lines 53-73) with: