azure-cli: az consumption budget create fails with offer type error message

Describe the Bug

Command Name az consumption budget create

Errors Command execution fails with error message: Subscription <subscription id> is not associated with EA offer type (Request ID: <request id>) which is weird because in the Azure Portal, I am able to create a budget within the same subscription with the same account. (Current offer type is Pay-as-you-go)

To Reproduce

  • in bash, login to Azure account
  • az consumption budget create --amount 100 --budget-name testbudget --category cost -e 2020-12-31 -s 2019-01-01 --time-grain annually --resource-group testgroup

Expected Behaviour

Budget is being created

Environment Summary

azure-cli                         2.0.68

command-modules-nspkg               2.0.3
core                              2.0.68
nspkg                              3.0.4
telemetry                          1.0.3

Extensions:
azure-cli-iot-ext                  0.7.1

Python (Linux) 3.6.5 (default, Jun 28 2019, 06:19:45) 
[GCC 7.4.0]

Ubuntu 18.04 LTS

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 19 (3 by maintainers)

Most upvoted comments

Good feedback. Agree. we will make the doc changes to reflect that current SDK (all languages) for budget supports EA subscriptions.

So, can I use these az consumption to create or get budgets if I am on MCA type of agreement? @ramaganesan-rg

Because now I can get them working

az consumption budget list
Command group 'consumption' is in preview. It may be changed/removed in a future release.
This operation is not supported in the version specified in the request. 
Please use version 2018-12-01-preview-preview or later. (Request ID: 7942b08e-49f8-4c35-95a2-0ac236937c01)

OK, in case it helps others, I am sharing my workaround using New-AzResource (similar to @axelwogawa 's brilliant workaround, which pointed me in the right direction):

$budgetProperties = @{}
$alertsList = @(75,85,95)
$budgetProperties = [ordered]@{
    'amount' = $amount
    'category' = "Cost"
    'name' = $budgetName
    'notifications' = @{}
    'timeGrain' =$timeGrain
    'timePeriod' = @{
        'startDate' = $startDate.ToString("yyyy-MM-dd")
        'endDate' = $endDate.ToString("yyyy-MM-dd")
    }
}

$notificationHash =@{}
Foreach ($threshold in $alertsList) {
    $notificationHash = @{
            "At$threshold" = [ordered]@{
                'enabled' = $true
                'operator' = "GreaterThan"
                'threshold' = $threshold
                'contactEmails' = @("email1@gmail.com","email2@hotmail.com")
            }
    } 
    $budgetProperties['notifications'] += $notificationHash
}

New-AzResource -ResourceName $budgetName -ResourceGroupName $resourceGroupName -ResourceType "Microsoft.Consumption/budgets" -Properties $budgetProperties -Force -ErrorAction SilentlyContinue

The above uses a Foreach loop to create the nested hash with as many thresholds as you may need (in this example I have 3, declared in a list), and then uses New-AzResource to submit the main hash in -Properties.

BTW: you will get the missing certificate error, as confirmed by @zikalino. That is why I added -ErrorAction SilentlyContinue at the end.

I hope this helps others!

FYI, this seems to be an API-version issue on the various tools. The Azure REST API itself works like a charm as a workaround:

Budgets - Create Or Update

Can reproduce this with the latest Azure PowerShell modules as well:

Set-AzConsumptionBudget -Name "MyBudget" -Amount 1000 -Debug

Body:
{
  "error": {
    "code": "400",
    "message": "Subscription <GUID> is not associated with EA offer type (Request ID: <GUID>)"
  }
}