Azure Query

Azure Query

Certified

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.

yaml
type: io.kestra.plugin.azure.billing.Query

Get last month's actual cost per resource group and log the total.

yaml
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.

yaml
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
SubTypestring

Aggregation columns

Required. Cost columns to sum, for example Cost, PreTaxCost, CostUSD or UsageQuantity. At least one column must be given.

Possible Values
ActualCostAmortizedCostUsage

Cost type

Required. ActualCost, AmortizedCost or Usage.

Possible Values
DailyMonthlyNone

Granularity

Daily, Monthly, or None for a single total per group.

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}.

Azure AD tenant ID (GUID)

Possible Values
MonthToDateBillingMonthToDateTheLastMonthTheLastBillingMonthWeekToDateCustom

Timeframe

Custom requires startDate and endDate. The Billing* timeframes are only meaningful at EA/MCA billing scopes.

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.

Definitions
assetFailureBehaviorstring
Possible Values
IGNOREFAILWARN

Asset 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.

enableAutobooleanstring

Whether to auto-register assets referenced dynamically at runtime that are not statically declared in inputs or outputs.

inputsarray

The assets consumed as inputs.

id*string
Min length1
typestring
outputs

The assets produced as outputs.

id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*string
Min length1

Custom asset type

descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150

Client ID of the Azure AD application

Application (client) ID used for service principal authentication.

Client secret for the Azure AD application

Secret value associated with the client ID; store in a Kestra secret.

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.

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.

DefaultSTORE
Possible Values
STOREFETCHFETCH_ONENONE

Fetch strategy

Default STORE writes all rows to internal storage. FETCH returns all rows, FETCH_ONE the first row, NONE only the totals.

SubTypestring

Group by

Up to 2 groupings. A plain value is a dimension (e.g. ResourceGroupName, ServiceName, ResourceLocation, SubscriptionName), TAG: <key> groups by a tag.

Default10

Maximum number of pages

Stops after this many requests (following nextLink) and logs a warning if more rows were available.

PEM-encoded certificate content for client authentication

PEM text for certificate-based auth; alternative to clientSecret.

Start date

First day of a Custom timeframe, inclusive, as yyyy-MM-dd.

SubTypenumber

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.

SubTypeobject

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.

First row

Single row when fetchType is FETCH_ONE.

SubTypeobject

Rows

All rows when fetchType is FETCH, keyed by the column names returned by Azure, e.g. Cost, UsageDate, ResourceGroupName, Currency.

Row count

Number of rows returned by Cost Management.

Truncated

True when maxPages was reached before all rows were read.

Currency

Currency of the costs, from the Currency column, e.g. USD or EUR. Null when the rows are in more than one currency.

Formaturi

Stored data URI

Internal storage URI of an ION file with all rows when fetchType is STORE.

Unitrows

Number of rows fetched or stored.

Unitrequests

Number of Cost Management requests made.