Azure / Azure/azure-powershell

Using New-AzCostManagementExport produces error - Request properties validation failed: Invalid definition type 'AmortizedCost'; valid values: 'Usage'

Open
#19,453 4 comments 0 reactions 0 assignees View on GitHub
bug Cost Management - UsageDetailsAndExport Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
3d 14h
Merged PRs (30d)
54

Description

### Description

Using New-AzCostManagementExport for with DefinitionType - AmortizedCost is producing the error - Request properties validation failed: Invalid definition type 'AmortizedCost'; valid values: 'Usage'.

Looks like the PS is using the api-version 2020-06-01 which was reported the same issue - https://github.com/Azure/azure-cli-extensions/issues/2021. This needs to be connected to the new api version.

see below the debug output of the same

DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /providers/Microsoft.Management/managementGroups/<>/providers/Microsoft.CostManagement/exports/AmortizedCostsMonthly?api-version=2020-06-01
DEBUG: RequestCreated: /providers/Microsoft.Management/managementGroups/<>/providers/Microsoft.CostManagement/exports/AmortizedCostsMonthly?api-version=2020-06-01
DEBUG: HeaderParametersAdded:
DEBUG: BodyContentSet:
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:https://management.azure.com/providers/Microsoft.Management/managementGroups/<>/providers/Microsoft.CostManagement/exports/AmortizedCostsMonthly?api-version=2020-06-01      

Headers:
x-ms-unique-id                : 11,12
x-ms-client-request-id        : <>
CommandName                   : New-AzCostManagementExport
FullCommandName               : New-AzCostManagementExport_CreateExpanded
ParameterSetName              : __AllParameterSets
User-Agent                    : AzurePowershell/v0.0.0,PSVersion/v5.1.22000.832,Az.CostManagement/0.2.0

Body:
{  "properties": {    "deliveryInfo": {      "destination": {        "resourceId": "/subscriptions/<>/resourceGroups/<>/providers/Microsoft.Storage/storageAccounts/<>",        "container": "monthlycntracmexports",        "rootFolderPath": "<>"      }    },    "definition": {      "dataSet": {        "granularity": "Daily"      },      "type": "AmortizedCost",      "timeframe": "TheLastBillingMonth"    },    "format": "Csv",    "schedule": {      "recurrencePeriod": {        "from": "2022-09-09T12:20:45.358732+03:00",        "to": "2023-09-09T12:20:45.358732+03:00"      },      "status": "Active",      "recurrence": "Monthly"    }  }
}

DEBUG: BeforeCall:
DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
BadRequest

Headers:
Pragma                        : no-cache
session-id                    : <>
x-ms-request-id               : <>
x-ms-correlation-request-id   : <>
x-ms-client-request-id        : <>
x-ms-ratelimit-remaining-tenant-reads: 11996
x-ms-routing-request-id       : <>
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Fri, 09 Sep 2022 09:21:34 GMT
X-Powered-By                  : ASP.NET

Body:
{  "error": {    "code": "400",    "message": "Request properties validation failed: Invalid definition type 'AmortizedCost'; valid values: 'Usage'.\r\n (Request ID: <>)"  }
}

DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:

### Issue script & Debug output

```PowerShell
Body:
{  "error": {    "code": "400",    "message": "Request properties validation failed: Invalid definition type 'AmortizedCost'; valid values: 'Usage'.\r\n (Request ID: <>)"  }
}
```

### Environment data

```PowerShell
Name Value
---- -----
PSVersion 5.1.22000.832
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22000.832
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
```

### Module versions

```PowerShell
PS C:\Users\rabuchep> Get-Module AZ*

ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.10.0 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}
Script 0.2.0 Az.CostManagement {Get-AzCostManagementExport, Get-AzCostManagementExportExecutionHistory, Invoke-AzCostManagementExecuteExport, Invoke-AzCostManagementQuery...}
```

### Error output

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the New-AzCostManagementExport entry point in the Az.CostManagement module and trace where api-version 2020-06-01 is selected. Reproduce the request using DefinitionType AmortizedCost and compare it with the newer API version referenced in the issue. Done means the cmdlet sends a supported API request and accepts the AmortizedCost definition without the validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, powershell
Domain
cloud, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.