
Azure Query
CertifiedQuery Azure cost and usage with Cost Management
Azure Query
Query Azure cost and usage with Cost Management
Calls the Cost Management Query - Usage API on a scope and returns one row per period and group.
The API is free but rate limited per scope, so request only the columns and groupings you need and keep
maxPages low.
type: io.kestra.plugin.azure.billing.QueryExamples
Get last month's actual cost per resource group and log the total.
id: azure_monthly_cost_by_rg
namespace: company.finops
tasks:
- id: cost
type: io.kestra.plugin.azure.billing.Query
scope: "/subscriptions/{{ secret('AZURE_SUBSCRIPTION_ID') }}"
costType: ActualCost
timeframe: TheLastMonth
granularity: None
aggregations:
- Cost
groupBy:
- ResourceGroupName
fetchType: FETCH
- id: log_total
type: io.kestra.plugin.core.log.Log
message: "Last month: {{ outputs.cost.costTotals.Cost }} {{ outputs.cost.unit }} over {{ outputs.cost.size }} resource groups"
pluginDefaults:
- type: io.kestra.plugin.azure
values:
tenantId: "{{ secret('AZURE_TENANT_ID') }}"
clientId: "{{ secret('AZURE_CLIENT_ID') }}"
clientSecret: "{{ secret('AZURE_CLIENT_SECRET') }}"
Store the daily cost of a custom period for one service, grouped by a tag.
id: azure_daily_cost_team
namespace: company.finops
tasks:
- id: cost
type: io.kestra.plugin.azure.billing.Query
scope: "/subscriptions/{{ secret('AZURE_SUBSCRIPTION_ID') }}"
costType: AmortizedCost
timeframe: Custom
startDate: "{{ now() | dateAdd(-7, 'DAYS') | date('yyyy-MM-dd') }}"
endDate: "{{ now() | dateAdd(-1, 'DAYS') | date('yyyy-MM-dd') }}"
granularity: Daily
aggregations:
- Cost
groupBy:
- "TAG:team"
dimensionFilter:
ServiceName:
- Storage
pluginDefaults:
- type: io.kestra.plugin.azure
values:
tenantId: "{{ secret('AZURE_TENANT_ID') }}"
clientId: "{{ secret('AZURE_CLIENT_ID') }}"
clientSecret: "{{ secret('AZURE_CLIENT_SECRET') }}"
Properties
aggregations *array
Aggregation columns
Required. Cost columns to sum, for example Cost, PreTaxCost, CostUSD or UsageQuantity. At least one column must be given.
costType *string
ActualCostAmortizedCostUsageCost type
Required. ActualCost, AmortizedCost or Usage.
granularity *string
DailyMonthlyNoneGranularity
Daily, Monthly, or None for a single total per group.
scope *string
Scope
Azure scope the costs or budgets belong to, for example /subscriptions/{subscriptionId},
/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName},
/providers/Microsoft.Management/managementGroups/{managementGroupId} or
/providers/Microsoft.Billing/billingAccounts/{billingAccountId}.
tenantId *string
Azure AD tenant ID (GUID)
timeframe *string
MonthToDateBillingMonthToDateTheLastMonthTheLastBillingMonthWeekToDateCustomTimeframe
Custom requires startDate and endDate. The Billing* timeframes are only meaningful at EA/MCA billing scopes.
assets
Assets this task consumes as inputs or produces as outputs, for lineage tracking and the asset graph (Enterprise Edition). A flow declaring this property on a task is rejected in the open-source edition.
io.kestra.core.models.assets.AssetsDeclaration
IGNOREFAILWARNAsset failure behavior
Behavior applied to the task state when a declared asset fails to render, emit, or be persisted (e.g. a lock conflict): FAIL escalates it to FAILED, WARN (default) warns it if it would otherwise succeed, IGNORE leaves the state untouched.
Whether to auto-register assets referenced dynamically at runtime that are not statically declared in inputs or outputs.
The assets consumed as inputs.
io.kestra.core.models.assets.AssetIdentifier
1The assets produced as outputs.
io.kestra.plugin.ee.assets.Dataset
1150{}1150io.kestra.plugin.ee.assets.File
1150{}1150io.kestra.plugin.ee.assets.Table
1150{}1150io.kestra.plugin.ee.assets.VM
1150{}1150io.kestra.core.models.assets.External
1150{}1150io.kestra.core.models.assets.Custom
11501Custom asset type
{}1150clientId string
Client ID of the Azure AD application
Application (client) ID used for service principal authentication.
clientSecret string
Client secret for the Azure AD application
Secret value associated with the client ID; store in a Kestra secret.
dimensionFilter object
Filter
Only include costs matching all entries (entries are ANDed). Keys use the same syntax as groupBy (ServiceName, TAG: team); the values listed for one key are ORed, so a cost matches when its value is any of them.
endDate string
End date
Last day of a Custom timeframe, as yyyy-MM-dd. Inclusive, like in the Cost Management API: the whole month of January is 2026-01-01 to 2026-01-31.
fetchType string
STORESTOREFETCHFETCH_ONENONEFetch strategy
Default STORE writes all rows to internal storage. FETCH returns all rows, FETCH_ONE the first row, NONE only the totals.
groupBy array
Group by
Up to 2 groupings. A plain value is a dimension (e.g. ResourceGroupName, ServiceName, ResourceLocation, SubscriptionName), TAG: <key> groups by a tag.
maxPages integerstring
10Maximum number of pages
Stops after this many requests (following nextLink) and logs a warning if more rows were available.
pemCertificate string
PEM-encoded certificate content for client authentication
PEM text for certificate-based auth; alternative to clientSecret.
startDate string
Start date
First day of a Custom timeframe, inclusive, as yyyy-MM-dd.
Outputs
costTotals object
Cost totals
Sum of each aggregation column over all returned rows, keyed by column name (e.g. costTotals.Cost). Null when the rows are in more than one currency (possible at EA, MCA or CSP billing scopes): use costTotalsByCurrency then.
costTotalsByCurrency object
Cost totals by currency
Sum of each aggregation column per value of the Currency column, e.g. costTotalsByCurrency.EUR.Cost. Empty when the response has no Currency column.
row object
First row
Single row when fetchType is FETCH_ONE.
rows array
Rows
All rows when fetchType is FETCH, keyed by the column names returned by Azure, e.g. Cost, UsageDate, ResourceGroupName, Currency.
size integer
Row count
Number of rows returned by Cost Management.
truncated boolean
Truncated
True when maxPages was reached before all rows were read.
unit string
Currency
Currency of the costs, from the Currency column, e.g. USD or EUR. Null when the rows are in more than one currency.
uri string
uriStored data URI
Internal storage URI of an ION file with all rows when fetchType is STORE.
Metrics
fetch.rows counter
rowsNumber of rows fetched or stored.
requests counter
requestsNumber of Cost Management requests made.