Cost Allocation Rules - Create Or Update
Create/Update a rule to allocate cost between different resources within a billing account or enterprise enrollment.
PUT https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.CostManagement/costAllocationRules/{ruleName}?api-version=2024-08-01
URI Parameters
Name | In | Required | Type | Description |
---|---|---|---|---|
billing
|
path | True |
string |
BillingAccount ID |
rule
|
path | True |
string |
Cost allocation rule name. The name cannot include spaces or any non alphanumeric characters other than '_' and '-'. The max length is 260 characters. Regex pattern: |
api-version
|
query | True |
string |
The API version to use for this operation. |
Request Body
Name | Type | Description |
---|---|---|
properties |
Cost allocation rule properties |
Responses
Name | Type | Description |
---|---|---|
200 OK |
OK. The update request has succeeded. |
|
201 Created |
Created. The request has succeeded. |
|
Other Status Codes |
Error response describing why the operation failed. |
Security
azure_auth
Azure Active Directory OAuth2 Flow.
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
Name | Description |
---|---|
user_impersonation | impersonate your user account |
Examples
Cost |
Cost |
CostAllocationRulesCreateResourceGroup
Sample request
PUT https://management.azure.com/providers/Microsoft.Billing/billingAccounts/100/providers/Microsoft.CostManagement/costAllocationRules/testRule?api-version=2024-08-01
{
"properties": {
"description": "This is a testRule",
"status": "Active",
"details": {
"sourceResources": [
{
"resourceType": "Dimension",
"name": "ResourceGroupName",
"values": [
"sampleRG",
"secondRG"
]
}
],
"targetResources": [
{
"resourceType": "Dimension",
"policyType": "FixedProportion",
"name": "ResourceGroupName",
"values": [
{
"name": "destinationRG",
"percentage": 45
},
{
"name": "destinationRG2",
"percentage": 54
}
]
}
]
}
}
}
Sample response
{
"id": "providers/Microsoft.Billing/billingAccounts/100/providers/Microsoft.CostManagement/costAllocationRules/testRule",
"name": "testRule",
"type": "Microsoft.CostManagement/costAllocationRules",
"properties": {
"description": "This is a testRule",
"createdDate": "2020-06-18T22:21:51.1287144Z",
"updatedDate": "2020-06-18T22:21:51.1287144Z",
"status": "Creating",
"details": {
"sourceResources": [
{
"resourceType": "Dimension",
"name": "ResourceGroupName",
"values": [
"sampleRG"
]
}
],
"targetResources": [
{
"resourceType": "Dimension",
"policyType": "FixedProportion",
"name": "ResourceGroupName",
"values": [
{
"name": "destinationRG",
"percentage": 50
},
{
"name": "destinationRG2",
"percentage": 50
}
]
}
]
}
}
}
{
"id": "providers/Microsoft.Billing/billingAccounts/100/providers/Microsoft.CostManagement/costAllocationRules/testRule",
"name": "testRule",
"type": "Microsoft.CostManagement/costAllocationRules",
"properties": {
"description": "This is a testRule",
"createdDate": "2020-06-18T22:21:51.1287144Z",
"updatedDate": "2020-06-18T22:21:51.1287144Z",
"status": "Creating",
"details": {
"sourceResources": [
{
"resourceType": "Dimension",
"name": "ResourceGroupName",
"values": [
"sampleRG"
]
}
],
"targetResources": [
{
"resourceType": "Dimension",
"policyType": "FixedProportion",
"name": "ResourceGroupName",
"values": [
{
"name": "destinationRG",
"percentage": 50
},
{
"name": "destinationRG2",
"percentage": 50
}
]
}
]
}
}
}
CostAllocationRulesCreateTag
Sample request
PUT https://management.azure.com/providers/Microsoft.Billing/billingAccounts/100/providers/Microsoft.CostManagement/costAllocationRules/testRule?api-version=2024-08-01
{
"properties": {
"description": "This is a testRule",
"status": "Active",
"details": {
"sourceResources": [
{
"resourceType": "Tag",
"name": "category",
"values": [
"devops"
]
}
],
"targetResources": [
{
"resourceType": "Dimension",
"policyType": "FixedProportion",
"name": "ResourceGroupName",
"values": [
{
"name": "destinationRG",
"percentage": 33.33
},
{
"name": "destinationRG2",
"percentage": 33.33
},
{
"name": "destinationRG3",
"percentage": 33.34
}
]
}
]
}
}
}
Sample response
{
"id": "providers/Microsoft.Billing/billingAccounts/100/providers/Microsoft.CostManagement/costAllocationRules/testRule",
"name": "testRule",
"type": "Microsoft.CostManagement/costAllocationRules",
"properties": {
"description": "This is a testRule",
"createdDate": "2020-06-18T22:21:51.1287144Z",
"updatedDate": "2020-06-18T22:21:51.1287144Z",
"status": "Creating",
"details": {
"sourceResources": [
{
"resourceType": "Dimension",
"name": "ResourceGroupName",
"values": [
"sampleRG"
]
}
],
"targetResources": [
{
"resourceType": "Dimension",
"policyType": "FixedProportion",
"name": "ResourceGroupName",
"values": [
{
"name": "destinationRG",
"percentage": 50
},
{
"name": "destinationRG2",
"percentage": 50
}
]
}
]
}
}
}
{
"id": "providers/Microsoft.Billing/billingAccounts/100/providers/Microsoft.CostManagement/costAllocationRules/testRule",
"name": "testRule",
"type": "Microsoft.CostManagement/costAllocationRules",
"properties": {
"description": "This is a testRule",
"createdDate": "2020-06-18T22:21:51.1287144Z",
"updatedDate": "2020-06-18T22:21:51.1287144Z",
"status": "Creating",
"details": {
"sourceResources": [
{
"resourceType": "Dimension",
"name": "ResourceGroupName",
"values": [
"sampleRG"
]
}
],
"targetResources": [
{
"resourceType": "Dimension",
"policyType": "FixedProportion",
"name": "ResourceGroupName",
"values": [
{
"name": "destinationRG",
"percentage": 50
},
{
"name": "destinationRG2",
"percentage": 50
}
]
}
]
}
}
}
Definitions
Name | Description |
---|---|
Cost |
Method to use for allocating cost. FixedProportion indicates that cost will be split based on specified percentage values. |
Cost |
Target resources and allocation |
Cost |
Category of resource to use for allocation. |
Cost |
The cost allocation rule model definition |
Cost |
Resource details of the cost allocation rule |
Cost |
The properties of a cost allocation rule |
Error |
The details of the error. |
Error |
Error response indicates that the service is not able to process the incoming request. The reason is provided in the error message. Some Error responses:
|
Rule |
Current status of the rule. |
Source |
Source resources for cost allocation |
Target |
Target resources for cost allocation. |
CostAllocationPolicyType
Method to use for allocating cost. FixedProportion indicates that cost will be split based on specified percentage values.
Name | Type | Description |
---|---|---|
FixedProportion |
string |
CostAllocationProportion
Target resources and allocation
Name | Type | Description |
---|---|---|
name |
string |
Target resource for cost allocation |
percentage |
number |
Percentage of source cost to allocate to this resource. This value can be specified to two decimal places and the total percentage of all resources in this rule must sum to 100.00. |
CostAllocationResourceType
Category of resource to use for allocation.
Name | Type | Description |
---|---|---|
Dimension |
string |
Indicates an Azure dimension such as a subscription id or resource group name is being used for allocation. |
Tag |
string |
Allocates cost based on Azure Tag key value pairs. |
CostAllocationRuleDefinition
The cost allocation rule model definition
Name | Type | Description |
---|---|---|
id |
string |
Azure Resource Manager Id for the rule. This is a read ony value. |
name |
string |
Name of the rule. This is a read only value. |
properties |
Cost allocation rule properties |
|
type |
string |
Resource type of the rule. This is a read only value of Microsoft.CostManagement/CostAllocationRule. |
CostAllocationRuleDetails
Resource details of the cost allocation rule
Name | Type | Description |
---|---|---|
sourceResources |
Source resources for cost allocation. At this time, this list can contain no more than one element. |
|
targetResources |
Target resources for cost allocation. At this time, this list can contain no more than one element. |
CostAllocationRuleProperties
The properties of a cost allocation rule
Name | Type | Description |
---|---|---|
createdDate |
string |
Time at which the rule was created. Rules that change cost for the same resource are applied in order of creation. |
description |
string |
Description of a cost allocation rule. |
details |
Resource information for the cost allocation rule |
|
status |
Status of the rule |
|
updatedDate |
string |
Time at which the rule was last updated. |
ErrorDetails
The details of the error.
Name | Type | Description |
---|---|---|
code |
string |
Error code. |
message |
string |
Error message indicating why the operation failed. |
ErrorResponse
Error response indicates that the service is not able to process the incoming request. The reason is provided in the error message.
Some Error responses:
429 TooManyRequests - Request is throttled. Retry after waiting for the time specified in the "x-ms-ratelimit-microsoft.consumption-retry-after" header.
503 ServiceUnavailable - Service is temporarily unavailable. Retry after waiting for the time specified in the "Retry-After" header.
Name | Type | Description |
---|---|---|
error |
The details of the error. |
RuleStatus
Current status of the rule.
Name | Type | Description |
---|---|---|
Active |
string |
Rule is saved and impacting cost allocation. |
NotActive |
string |
Rule is saved but not used to allocate costs. |
Processing |
string |
Rule is saved and cost allocation is being updated. Readonly value that cannot be submitted in a put request. |
SourceCostAllocationResource
Source resources for cost allocation
Name | Type | Description |
---|---|---|
name |
string |
If resource type is dimension, this must be either ResourceGroupName or SubscriptionId. If resource type is tag, this must be a valid Azure tag |
resourceType |
Type of resources contained in this cost allocation rule |
|
values |
string[] |
Source Resources for cost allocation. This list cannot contain more than 25 values. |
TargetCostAllocationResource
Target resources for cost allocation.
Name | Type | Description |
---|---|---|
name |
string |
If resource type is dimension, this must be either ResourceGroupName or SubscriptionId. If resource type is tag, this must be a valid Azure tag |
policyType |
Method of cost allocation for the rule |
|
resourceType |
Type of resources contained in this cost allocation rule |
|
values |
Target resources for cost allocation. This list cannot contain more than 25 values. |