azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

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

Open raghu4sangeeth opened this issue 3 years ago • 3 comments

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/<<MGMTGROUP>>/providers/Microsoft.CostManagement/exports/AmortizedCostsMonthly?api-version=2020-06-01 DEBUG: RequestCreated: /providers/Microsoft.Management/managementGroups/<<MGMTGROUP>>/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/<<MGMTGROUP>>/providers/Microsoft.CostManagement/exports/AmortizedCostsMonthly?api-version=2020-06-01      

Headers: x-ms-unique-id                : 11,12 x-ms-client-request-id        : <<REQUESTID>> 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/<<SUBSCRIPTION>>/resourceGroups/<<RESOURCEGROUP>>/providers/Microsoft.Storage/storageAccounts/<<STORAGEACCOUNT>>",        "container": "monthlycntracmexports",        "rootFolderPath": "<<SUBSCRIPTION>>"      }    },    "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                    : <<SESSIONID>> x-ms-request-id               : <<REQUESTID>> x-ms-correlation-request-id   : <<REQUESTID>> x-ms-client-request-id        : <<REQUESTID>> x-ms-ratelimit-remaining-tenant-reads: 11996 x-ms-routing-request-id       : <<REQUESTID>> 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: <<REQUESTID>>)"  } }

DEBUG: ResponseCreated: DEBUG: BeforeResponseDispatch:

Issue script & Debug output

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

Environment data

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

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

raghu4sangeeth avatar Sep 09 '22 14:09 raghu4sangeeth

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @TiagoCrewGitHubIssues.

Issue Details

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/<<MGMTGROUP>>/providers/Microsoft.CostManagement/exports/AmortizedCostsMonthly?api-version=2020-06-01 DEBUG: RequestCreated: /providers/Microsoft.Management/managementGroups/<<MGMTGROUP>>/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/<<MGMTGROUP>>/providers/Microsoft.CostManagement/exports/AmortizedCostsMonthly?api-version=2020-06-01      

Headers: x-ms-unique-id                : 11,12 x-ms-client-request-id        : <<REQUESTID>> 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/<<SUBSCRIPTION>>/resourceGroups/<<RESOURCEGROUP>>/providers/Microsoft.Storage/storageAccounts/<<STORAGEACCOUNT>>",        "container": "monthlycntracmexports",        "rootFolderPath": "<<SUBSCRIPTION>>"      }    },    "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                    : <<SESSIONID>> x-ms-request-id               : <<REQUESTID>> x-ms-correlation-request-id   : <<REQUESTID>> x-ms-client-request-id        : <<REQUESTID>> x-ms-ratelimit-remaining-tenant-reads: 11996 x-ms-routing-request-id       : <<REQUESTID>> 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: <<REQUESTID>>)"  } }

DEBUG: ResponseCreated: DEBUG: BeforeResponseDispatch:

Issue script & Debug output

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

Environment data

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

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

Author: raghu4sangeeth
Assignees: -
Labels:

Service Attention, bug, Cost Management - UsageDetailsAndExport

Milestone: -

ghost avatar Sep 11 '22 12:09 ghost

@raghu4sangeeth Would you please post the cmdlet you executed so that we could reproduce it locally? Besides, according to https://github.com/Azure/azure-cli-extensions/issues/2021, the issue is reported from 2019-11-01 instead of 2020-06-01. CLI's solution is to upgrade version to 2020-0-01, which has been done by Azure PowerShell already.

dolauli avatar Sep 13 '22 01:09 dolauli

  $getExport = New-AzCostManagementExport -Debug -Scope "providers/Microsoft.Management/managementGroups/$($ManagementGroup)" `
            -Name $ExportName `
            -DefinitionTimeframe "TheLastBillingMonth" `
            -Format "Csv" `
            -DestinationResourceId "/subscriptions/$($Subscription)/resourceGroups/$($ResourceGroupName)/providers/Microsoft.Storage/storageAccounts/$(Y)" `
            -DestinationContainer $ContainerName `
            -DestinationRootFolderPath $Subscription `
            -DefinitionType "AmortizedCost" `
            -DatasetGranularity "Daily" `
            -RecurrencePeriodFrom $currentDate `
            -RecurrencePeriodTo $afterYear `
            -ScheduleRecurrence $ScheduleRecurrence `
            -ScheduleStatus "Active"

raghu4sangeeth avatar Sep 13 '22 07:09 raghu4sangeeth

this is still undocumented here https://learn.microsoft.com/en-us/cli/azure/costmanagement/export?view=azure-cli-latest#az-costmanagement-export-create there is no mention of rootFolderPath

az costmanagement export create \
    --name "TestExport" \
    --scope "subscriptions/xyz-baed-4017-abc9-45e4ebb182f3" \
    --storage-account-id="/subscriptions/abc-0537-4daf-87a2-96a5ffab49ee/resourceGroups/rg-csp-costs/providers/Microsoft.Storage/storageAccounts/aecspcosts" \
    --storage-container="exports" \
    --timeframe "MonthToDate"

(400) Request properties validation failed: Invalid deliveryInfo destination rootFolderPath; value cannot be empty or blank.
```

woutervanranst avatar Sep 12 '23 12:09 woutervanranst