Skip to main content

Azure Cost Management Exports

The Azure Cost Management Exports integration enables Massdriver to collect detailed billing data from your Azure subscription, allowing you to track costs by package and resource.

Prerequisites

  • Azure subscription with Cost Management access
  • OpenTofu installed
  • Permissions to create resource groups, storage accounts, and service principals

Setup

Step 1: Clone the Integration Module

git clone https://github.com/massdriver-cloud/integrations.git
cd integrations/azure-cost-management-exports

Step 2: Authenticate with Azure

az login
az account set --subscription "YOUR_SUBSCRIPTION_ID"

Step 3: Apply the Module

tofu init
tofu plan
tofu apply

Step 4: Retrieve Outputs

After applying, retrieve the configuration values:

tofu output -json massdriver_integration_config

This outputs:

{
"tenant_id": "abc123-...",
"subscription_id": "def456-...",
"client_id": "ghi789-...",
"client_secret": "***",
"storage_account_name": "mdcostsa1b2c3d4",
"container_name": "massdriver-costs-a1b2c3d4"
}

Step 5: Configure Massdriver

Provide the following values when configuring the integration in Massdriver:

FieldDescriptionSource
Tenant IDYour Azure AD tenanttenant_id output
Subscription IDAzure subscription to monitorsubscription_id output
Client IDService principal application IDclient_id output
Client SecretService principal secretclient_secret output
Storage Account NameWhere cost exports are storedstorage_account_name output
Container NameBlob container for exportscontainer_name output

Resources Created

The OpenTofu module creates:

ResourceNamePurpose
Resource Groupmassdriver-costs-{hash}Contains cost management resources
Storage Accountmdcosts{hash}Stores cost export files
Blob Containermassdriver-costs-{hash}Container for export CSV files
Cost Exportmassdriver-costsDaily cost export schedule
Azure AD Applicationmassdriver-cost-readerApp registration for Massdriver
Service Principal-Identity for Massdriver access
Role AssignmentStorage Blob Data ReaderRead access to cost exports

Service Principal Permissions

The service principal is granted minimal read-only access:

  • Role: Storage Blob Data Reader
  • Scope: The storage account containing cost exports

This follows the principle of least privilege - Massdriver can only read the exported cost data.

Export Configuration

The cost export is configured with:

  • Type: ActualCost (not forecasted)
  • Timeframe: MonthToDate
  • Granularity: Daily
  • Format: CSV
  • Schedule: Daily recurrence
note

All resources are created in the eastus region. Cost exports include all resources across all regions in the subscription.

Data Collection

Once enabled, Massdriver:

  1. Authenticates using the service principal credentials
  2. Lists blobs in the cost export container
  3. Downloads the latest export CSV
  4. Parses and aggregates costs by md-package tag
  5. Stores daily and monthly cost data

Data is collected every 24 hours.

Troubleshooting

Enable fails with "access_denied"

The service principal may not have the correct role assignment. Verify the Storage Blob Data Reader role is assigned to the storage account.

Enable fails with "container_not_found"

The blob container doesn't exist. Verify the OpenTofu module was applied successfully and the container name matches.

No cost data appears

  • Verify resources have the md-package tag applied
  • Cost exports take up to 24 hours to generate initially
  • Check the Azure portal to confirm exports are being written

Authentication errors

  • Verify the client secret hasn't expired
  • Confirm the service principal is in the correct tenant
  • Check that the subscription ID matches

Cleanup

To remove the integration resources:

cd integrations/azure-cost-management-exports
tofu destroy
danger

This will delete the storage account and all stored exports. Cost data already collected by Massdriver will be retained.