turbot / steampipe-plugin-azure

Use SQL to instantly query Azure resources across regions and subscriptions. Open source CLI. No DB required.
https://hub.steampipe.io/plugins/turbot/azure
Apache License 2.0
37 stars 17 forks source link

Add table azure_consumption_usage Closes #668 #721

Closed ParthaI closed 8 months ago

ParthaI commented 8 months ago

Integration test logs

Logs ``` N/A ```

Example query results

Results ``` > select name, id, metric, kind, legacy_usage_detail ->> 'BillingAccountID' as billing_account_id, legacy_usage_detail ->> 'BillingAccountName' as billing_account_name, legacy_usage_detail ->> 'BillingPeriodStartDate' as billing_period_start_date, legacy_usage_detail ->> 'BillingPeriodEndDate' as billing_period_end_date, legacy_usage_detail ->> 'Cost' as cost, legacy_usage_detail ->> 'BillingCurrency' as billing_currency, legacy_usage_detail ->> 'ResourceID' as resource_id from azure_consumption_usage where kind = 'legacy' and metric = 'actualcost' and filter = 'properties/resourceGroup eq ''turbot_rg'''; +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+--------------------+> | name | id | metric | kind | billing_account_id |> +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+--------------------+> | 8fcb63ea-9679-2346-1d17-a21fd4a5d929 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202306/providers/Microsoft.Consumption/usageDetails/8fcb63ea-9679-2346-1d17-a21fd4a5d929 | actualcost | legacy | |> | 8ea76821-b7ed-5ba8-d7eb-da9465585ba1 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202307/providers/Microsoft.Consumption/usageDetails/8ea76821-b7ed-5ba8-d7eb-da9465585ba1 | actualcost | legacy | |> | ce00701f-76f0-4ac3-dbc0-cf27308b05f0 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202308/providers/Microsoft.Consumption/usageDetails/ce00701f-76f0-4ac3-dbc0-cf27308b05f0 | actualcost | legacy | |> | 1069146f-0197-5c15-9358-ee2c1c2685ec | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202308/providers/Microsoft.Consumption/usageDetails/1069146f-0197-5c15-9358-ee2c1c2685ec | actualcost | legacy | |> | 82ceef73-5ade-820f-ac86-d44e5d880880 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202307/providers/Microsoft.Consumption/usageDetails/82ceef73-5ade-820f-ac86-d44e5d880880 | actualcost | legacy | |> | 65b971cd-777a-4a44-ffa3-faa9c806efb2 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202303/providers/Microsoft.Consumption/usageDetails/65b971cd-777a-4a44-ffa3-faa9c806efb2 | actualcost | legacy | |> | c5836a2c-8d80-e5e1-8b80-8948642e491e | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202303/providers/Microsoft.Consumption/usageDetails/c5836a2c-8d80-e5e1-8b80-8948642e491e | actualcost | legacy | |> > select name, id, metric, kind, legacy_usage_detail ->> 'BillingAccountID' as billing_account_id, legacy_usage_detail ->> 'BillingAccountName' as billing_account_name, legacy_usage_detail ->> 'BillingPeriodStartDate' as billing_period_start_date, legacy_usage_detail ->> 'BillingPeriodEndDate' as billing_period_end_date, legacy_usage_detail ->> 'Cost' as cost, legacy_usage_detail ->> 'BillingCurrency' as billing_currency from azure_consumption_usage where kind = 'legacy' and metric = 'actualcost' order by cost desc limit 10; +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+--------------------+> | name | id | metric | kind | billing_account_id |> +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+--------------------+> | 92e9a512-1299-4154-9522-18d5133f26a5 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202309/providers/Microsoft.Consumption/usageDetails/92e9a512-1299-4154-9522-18d5133f26a5 | actualcost | legacy | |> | aaaf6300-790c-f3f2-b4ac-12a3f4edfd7e | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202306/providers/Microsoft.Consumption/usageDetails/aaaf6300-790c-f3f2-b4ac-12a3f4edfd7e | actualcost | legacy | |> | e9b6ecd8-4241-fd8c-de73-08fa9e75bdc4 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202306/providers/Microsoft.Consumption/usageDetails/e9b6ecd8-4241-fd8c-de73-08fa9e75bdc4 | actualcost | legacy | |> | 20811d99-2e75-598a-0a50-ab9e8590b9a6 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202306/providers/Microsoft.Consumption/usageDetails/20811d99-2e75-598a-0a50-ab9e8590b9a6 | actualcost | legacy | |> | 902e258e-9efd-7262-8cdd-88ec23970bd0 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202306/providers/Microsoft.Consumption/usageDetails/902e258e-9efd-7262-8cdd-88ec23970bd0 | actualcost | legacy | |> | 67e0fa5d-a9d0-e20f-97cc-9dfcacad7c36 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202303/providers/Microsoft.Consumption/usageDetails/67e0fa5d-a9d0-e20f-97cc-9dfcacad7c36 | actualcost | legacy | |> | 5273fe26-057e-32cd-847e-ce374ab33921 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202304/providers/Microsoft.Consumption/usageDetails/5273fe26-057e-32cd-847e-ce374ab33921 | actualcost | legacy | |> | 5273fe26-057e-32cd-847e-ce374ab33921 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202304/providers/Microsoft.Consumption/usageDetails/5273fe26-057e-32cd-847e-ce374ab33921 | actualcost | legacy | |> | 104b0770-b055-9a1c-db42-781dcd040c33 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202303/providers/Microsoft.Consumption/usageDetails/104b0770-b055-9a1c-db42-781dcd040c33 | actualcost | legacy | |> | 104b0770-b055-9a1c-db42-781dcd040c33 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202303/providers/Microsoft.Consumption/usageDetails/104b0770-b055-9a1c-db42-781dcd040c33 | actualcost | legacy | |> +--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+--------------------+> > select * from azure_consumption_usage where expand = 'properties/additionalInfo1' limit 5 [ { "_ctx": { "connection_name": "azure", "steampipe": { "sdk_version": "5.8.0" } }, "akas": [ "azure:///subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202311/providers/Microsoft.Consumption/usageDetails/00f527fe-d79d-0ca8-2960-fdec1e27efbf", "azure:///subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/microsoft.billing/billingperiods/202311/providers/microsoft.consumption/usagedetails/00f527fe-d79d-0ca8-2960-fdec1e27efbf" ], "cloud_environment": "AzurePublicCloud", "etag": null, "expand": "properties/additionalInfo1", "filter": null, "id": "/subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202311/providers/Microsoft.Consumption/usageDetails/00f527fe-d79d-0ca8-2960-fdec1e27efbf", "kind": "legacy", "legacy_usage_detail": { "AccountName": null, "AccountOwnerID": null, "AdditionalInfo": null, "BillingAccountID": null, "BillingAccountName": null, "BillingCurrency": "USD", "BillingPeriodEndDate": "2023-11-11T00:00:00Z", "BillingPeriodStartDate": "2023-10-12T00:00:00Z", "BillingProfileID": "/subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1", "BillingProfileName": "newwarriors AAA", "ChargeType": "Usage", "ConsumedService": "Microsoft.Storage", "Cost": "0.000005338078292", "CostCenter": null, "Date": "2023-10-16T00:00:00Z", "EffectivePrice": "0.00355871886121", "Frequency": "UsageBased", "InvoiceSection": null, "IsAzureCreditEligible": false, "MeterDetails": null, "MeterID": "0b248445-aa24-4fe8-a794-a174929327bd", "OfferID": "MS-AZR-0003P", "PartNumber": null, "PlanName": null, "Product": "Tiered Block Blob - All Other Operations - US East", "ProductOrderID": null, "ProductOrderName": null, "PublisherName": null, "PublisherType": "Azure", "Quantity": "0.0015", "ReservationID": null, "ReservationName": null, "ResourceGroup": "nist-test_group", "ResourceID": "/subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/resourceGroups/nist-test_group/providers/Microsoft.Storage/storageAccounts/testimmutablecontainer", "ResourceLocation": "US East", "ResourceName": "testimmutablecontainer", "ServiceInfo1": null, "ServiceInfo2": null, "SubscriptionID": "3510ae4d-530b-497d-8f30-53b9616fc6c1", "SubscriptionName": "newwarriors AAA", "Term": null, "UnitPrice": "0" }, "metric": null, "modern_usage_detail": null, "name": "00f527fe-d79d-0ca8-2960-fdec1e27efbf", "scope": "/subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/", "subscription_id": "3510ae4d-530b-497d-8f30-53b9616fc6c1", "tags": { "foo": "bar" }, "title": "00f527fe-d79d-0ca8-2960-fdec1e27efbf", "type": "Microsoft.Consumption/usageDetails" }, ```