Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions terraform/azure_billing/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions terraform/azure_billing/azure-provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Provider configuration for billing-scoped resources
# Billing APIs are tenant-scoped; subscription_id is only needed for authentication
provider "azurerm" {
features {}

# Using FXCI subscription for authentication
subscription_id = "108d46d5-fe9b-4850-9a7d-8c914aa6c1f0"
tenant_id = "c0dc8bb0-b616-427e-8217-9513964a145b"
}

provider "azapi" {
subscription_id = "108d46d5-fe9b-4850-9a7d-8c914aa6c1f0"
tenant_id = "c0dc8bb0-b616-427e-8217-9513964a145b"
}
8 changes: 8 additions & 0 deletions terraform/azure_billing/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
backend "s3" {
bucket = "relops-tf-states"
key = "azure_billing.tfstate"
use_lockfile = true
region = "us-west-2"
}
}
123 changes: 123 additions & 0 deletions terraform/azure_billing/finops.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Cost exports for billing-scoped resources (invoice sections, billing profiles)
# These are not tied to a specific subscription

locals {
# Billing hierarchy
billing_account_id = "05ef9068-c74c-54a9-5b8f-82f7fb8b32cd:6e104178-9e3c-470c-9787-8ef53f372665_2019-05-31"
mozilla_billing_profile_id = "GRUW-TLBL-BG7-PGB"

# Invoice sections under mozilla billing profile
anonym_invoice_section_id = "RUDC-GV4R-PJA-PGB"
}

# Storage account for cost exports (managed in azure_fxci)
data "azurerm_storage_account" "finops" {
name = "safinopsdata"
resource_group_name = "rg-azure-cost-mgmt"
}

import {
to = azapi_resource.anonym_cost_export_actual
id = "/providers/Microsoft.Billing/billingAccounts/${local.billing_account_id}/billingProfiles/${local.mozilla_billing_profile_id}/invoiceSections/${local.anonym_invoice_section_id}/providers/Microsoft.CostManagement/exports/anonym_daily-actual-cost"
}

import {
to = azapi_resource.anonym_cost_export_amortized
id = "/providers/Microsoft.Billing/billingAccounts/${local.billing_account_id}/billingProfiles/${local.mozilla_billing_profile_id}/invoiceSections/${local.anonym_invoice_section_id}/providers/Microsoft.CostManagement/exports/anonym-amortized-cost"
}

# Anonym invoice section - Actual Cost export
resource "azapi_resource" "anonym_cost_export_actual" {
type = "Microsoft.CostManagement/exports@2025-03-01"
name = "anonym_daily-actual-cost"
parent_id = "/providers/Microsoft.Billing/billingAccounts/${local.billing_account_id}/billingProfiles/${local.mozilla_billing_profile_id}/invoiceSections/${local.anonym_invoice_section_id}"

identity {
type = "SystemAssigned"
}

body = {
properties = {
schedule = {
status = "Active"
recurrence = "Daily"
recurrencePeriod = {
from = "2024-10-01T00:00:00Z"
to = "2050-02-01T00:00:00Z"
}
}
format = "Csv"
compressionMode = "None"
dataOverwriteBehavior = "CreateNewReport"
deliveryInfo = {
destination = {
type = "AzureBlob"
resourceId = data.azurerm_storage_account.finops.id
container = "cost-management"
rootFolderPath = "anon_daily"
}
}
partitionData = true
definition = {
type = "ActualCost"
timeframe = "MonthToDate"
dataSet = {
granularity = "Daily"
configuration = {
columns = []
dataVersion = "2021-10-01"
filters = []
}
}
}
}
}
}

# Anonym invoice section - Amortized Cost export
resource "azapi_resource" "anonym_cost_export_amortized" {
type = "Microsoft.CostManagement/exports@2025-03-01"
name = "anonym-amortized-cost"
parent_id = "/providers/Microsoft.Billing/billingAccounts/${local.billing_account_id}/billingProfiles/${local.mozilla_billing_profile_id}/invoiceSections/${local.anonym_invoice_section_id}"

identity {
type = "SystemAssigned"
}

body = {
properties = {
schedule = {
status = "Active"
recurrence = "Daily"
recurrencePeriod = {
from = "2024-10-01T00:00:00Z"
to = "2050-02-01T00:00:00Z"
}
}
format = "Csv"
compressionMode = "None"
dataOverwriteBehavior = "CreateNewReport"
deliveryInfo = {
destination = {
type = "AzureBlob"
resourceId = data.azurerm_storage_account.finops.id
container = "cost-management"
rootFolderPath = "anon_daily_amortized"
}
}
partitionData = true
definition = {
type = "AmortizedCost"
timeframe = "MonthToDate"
dataSet = {
granularity = "Daily"
configuration = {
columns = []
dataVersion = "2021-10-01"
filters = []
}
}
}
}
}
}
12 changes: 12 additions & 0 deletions terraform/azure_billing/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_version = ">= 0.15"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 4"
}
azapi = {
source = "azure/azapi"
}
}
}