Home› Blog› Week 8 — The Cheapest Log Is the One You Never Ing…
Azure Weekly Lab Azure Terraform

Week 8 — The Cheapest Log Is the One You Never Ingested

Ingestion is the biggest surprise bill in Azure. Most workspaces get created with defaults and never looked at again. This one makes every cost decision explicit — and measures what they're worth.

Verified against current vendor documentation on 9 October 2026. Pricing, limits and API behaviour were checked against the official docs on that date. Cloud services change fast — if you are reading this much later, treat the specifics as a starting point and re-check the linked sources.
Log Analytics Azure Monitor Data Collection Rules KQL Terraform
Azure Platform Engineering Lab · Week 8 of 52

Lab Overview

A Log Analytics workspace costs nothing to own. It costs money the moment something sends it data, and by then the decisions that set the price — which table, which plan, what gets filtered — have already been made for you by defaults.

This week builds the workspace every later week in the lab reports into, and makes those three decisions on purpose.

DifficultyAdvanced — custom tables and ingest-time transformations, and two of the steps are only reachable through azapi
Time to completeOne to two hours. Part of it is unavoidable waiting: the role assignment took five minutes to propagate before ingestion stopped returning 403
Deployment methodTerraform (azurerm + azapi), state in HCP Terraform, local execution
Source and lab guideweek-08-log-analytics on GitHub — exact prerequisites, variables, commands, expected outputs and cleanup

This week is designed to stay up — see Cleanup.

Cloud Services and Concepts

ServicePurpose hereWhat it is
Log Analytics workspace Where logs land and are queried Holds tables of log data queried with KQL. Billed per GB ingested, and on some table plans again for what each query scans.
Table plan The lever that sets the price Analytics costs the most to ingest and nothing to query; Basic and Auxiliary are far cheaper to ingest and bill per GB a query scans. The ingestion prices span roughly 46×.
Data collection rule Runs one line of KQL before anything is stored Sits between the sender and the table and can transform or drop each row at ingest. Rows it drops are never billed at all.
Data collection endpoint Where the sender actually posts The HTTPS endpoint through which the collection rule is reached.
Daily cap A circuit breaker, not a cost strategy Stops collection once the workspace has taken a set volume that day. It protects the bill by throwing data away, so when it trips the logs you wanted are gone.

Architecture and Workflow

Architecture diagram. One hundred rows are sent to a data collection endpoint and rule, where a single line of KQL is applied at ingest time. Eighty rows are dropped there: never stored, never billed, and never counted against the daily cap. The twenty rows that are kept land in a Log Analytics workspace holding two custom tables on deliberately different plans, an Analytics table for the alerting path whose queries are free to run, and a Basic table for the incident path which is cheaper to ingest but bills per gigabyte scanned. A scheduled query alert watches for the daily cap being reached, because a cap that trips in silence is data loss nobody noticed.
The whole week on one page. 100 rows in, 20 out: the transformation runs inside the collection rule, so the 80 dropped rows are never stored, never billed and never counted by the cap. The two tables sit on deliberately different plans, which is the second lever.

Prerequisites

  • Permissions: Contributor and User Access Administrator on the subscription. The second is not optional here — the lab grants Monitoring Metrics Publisher on the data collection rule, and Contributor cannot create role assignments.
  • A mailbox you can receive at. alert_email is a required variable with no default, because a daily cap that trips silently is data loss. It lives in terraform.tfvars, which is gitignored.
  • Terraform ≥ 1.10, with azurerm 5.x and azapi 2.x. azapi is not optional: azurerm_log_analytics_workspace_table has nowhere to put a schema, so the two custom tables have to be created through ARM directly.
  • Two resource providers on the subscription — Microsoft.OperationalInsights and Microsoft.Insights. The deploy script registers them.
  • No prior week is required. This is the one every later week depends on, not the other way round.

Every variable, the role scope and the table schemas are in the lab guide on GitHub, which is the reproducible half of this write-up.

Implementation

1. The HCP workspace, created first and deliberately

This is a step, not a side effect. Creating it explicitly means setting its execution mode at birth:

POST /api/v2/organizations/Katta/workspaces
{ "name": "azure-week-08-dev", "execution-mode": "local" }

created: azure-week-08-dev | execution-mode: local

Week 7 let terraform init create the workspace instead, and HCP defaulted it to remote execution. The plan then ran on HCP's servers, where there is no Azure CLI and no credentials, and failed with az: executable file not found in $PATH — an error that sends you debugging the wrong machine entirely.

HCP Terraform workspace azure-week-08-dev in the Azure Platform Lab project, showing 10 resources, 4 outputs, Terraform v1.16.5, execution mode Local, and the resource list including the Log Analytics workspace, data collection endpoint, data collection rule, scheduled query alert and role assignment
Checkpoint: Execution mode: Local is the setting this whole step exists to get right — it is what keeps Azure credentials off HCP, since the only acceptable remote alternative is OIDC rather than an uploaded client secret. The resource list is also the fastest way to confirm the azapi tables and the role assignment both made it in.

2. The Terraform

The Terraform file tree for this week: terraform/ with versions.tf, variables.tf, a 144-line main.tf holding the workspace and two custom tables, a 120-line ingestion.tf holding the endpoint, collection rule and transform, and outputs.tf; plus three scripts, each annotated with its job and line count
Every file, and what it is for. main.tf answers "where does the data land, and how is it priced". ingestion.tf answers "what gets in". Changing what data costs and changing what arrives are rarely the same decision, so they are rarely the same file.

Decision one: table plans follow how data is used, not how big it is. These are the prices Azure quotes for this workspace:

PlanPer GB ingestedQueriesInteractive window
Analytics$2.76free to runup to 2 years
Basic$0.60bill per GB scannedfixed 30 days
Auxiliary / Lake$0.06bill per GB scannedfull retention

A 46× spread — and queries are where it gets interesting. Analytics costs the most to ingest and nothing to query. Basic and Auxiliary are cheap to ingest and bill per GB scanned. So a cheap table queried often can cost more than an expensive one queried rarely.

resource "azapi_resource" "alerts_table" {      # the alerting path
  name = "PlatformLogs_CL"
  body = { properties = { plan = "Analytics",   # queried constantly
                          retentionInDays = 30,
                          totalRetentionInDays = 90, ... } }
}

resource "azapi_resource" "verbose_table" {     # the incident path
  name = "PlatformVerbose_CL"
  body = { properties = { plan = "Basic",       # read when something breaks
                          totalRetentionInDays = 365, ... } }
}

Decision two: the daily cap is a backstop, not a strategy. Microsoft's own guidance says it "should not be used as a primary mechanism to filter or reduce data" — when a cap trips, collection stops. The money is already spent and now you have lost the logs as well. It is set at 1 GB/day, far above anything this lab sends: a cap set near normal volume trips on a normal busy day.

Decision three: the transformation is the actual control. One line of KQL, applied at ingest:

transform_kql = "source | where Level in ('Warning','Error','Critical')"

Anything below Warning is never written, so it is never billed — and the cap never has to count it.

Rows below Warning are never written, never stored and never billed. The cap never has to count them, because as far as the bill is concerned they never arrived.

3. Deploying it

./scripts/deploy.sh      # registers two providers, then applies
./scripts/validate.sh    # 5 checks; #4 sends 100 rows and counts survivors
./scripts/cleanup.sh     # refuses - this week stays up. --force to mean it

4. What appeared in the portal

Azure portal Tables blade showing PlatformLogs_CL as a custom table on the Analytics plan with 30 days interactive and 90 days total retention, PlatformVerbose_CL as a custom table on the Basic plan with no interactive retention and 1 year total, and six built-in Azure tables all on the Analytics default
Checkpoint: the two custom tables on the plans the Terraform asked for — PlatformLogs_CL on Analytics with 30 days interactive, PlatformVerbose_CL on Basic with none. The six built-in tables are all stuck on Analytics, which is exactly why this week creates its own.

This is the design in one screen. Two custom tables on deliberately different plans — and note PlatformVerbose_CL shows no interactive retention at all, because Basic fixes the query window at 30 days. Every built-in table sits on the Analytics default beside them, which is what you get if you never make the decision.

Azure portal Usage and estimated costs blade showing pay-as-you-go as the current pricing tier with Analytics at 2.76 dollars per GB, Basic at 0.60 and Auxiliary at 0.06, a note that the workspace has a daily cap configured, and the 100 GB per day commitment tier at 20 percent discount
What the plans are worth, in Azure's own numbers: $2.76/GB for Analytics against $0.60 for Basic. The cap is configured here too — and the commitment tier that offers a 20% discount starts at 100 GB/day, far above anything this lab produces.

Azure's own numbers, and a note confirming the cap is configured. The commitment tier below is worth reading too: 100 GB/day for 20% off. A lab never reaches that, so pay-as-you-go is the honest choice here and the discount is not claimed.

Validation and Evidence

A successful terraform apply proves the workspace, the rule and the tables exist. It proves nothing about whether the transformation actually filters — and a transformation that filters nothing looks identical in the portal to one that filters everything.

TestExpectedActualStatus
Workspace pricing and capPerGB2018 with a daily cap setpay-as-you-go, cap setPASS
Table plansPlatformLogs_CL on Analytics, PlatformVerbose_CL on Basicboth on their intended plansPASS
Collection endpoint and ruleboth resolveboth resolvedPASS
Ingestion acceptedHTTP 204204PASS
Transformation drops rows before billingonly Warning and above stored — 20 of the 100 sent20 stored, 80 dropped at ingest and never billedPASS
The cap has an alarm that firesan enabled query rule wired to an action groupenabled rule, attachedPASS

What the test actually sends

A transformation that filters nothing looks identical in the portal to one that filters everything. The only way to know is to send known data and count what survived:

4. The transformation drops rows BEFORE they are billed
   sending 100 rows, 20 of them Warning or above
   ingestion API returned HTTP 204
   rows stored: 20 of 100 sent
   RESULT: 20 stored, 80 dropped at ingest and never billed

── 5 passed, 0 failed ──

The two levers compound. Drop 80% at ingest, then put what survives on the right plan, and the difference is between paying $2.76 a GB for everything and paying it for the fifth you actually query.

Security and Cost

Security

  • Resource-only permissions. Reading one resource's logs needs no grant on the workspace. Workspace Reader hands over every log from every subscription at once.
  • Shared keys off. The workspace ID and key pair is a password that never expires and records nothing about who used it. Callers use Entra tokens.
  • Publisher scoped to the DCR, not the resource group. Getting that role wrong means someone forging logs.
  • The cap has an alarm, because one that trips in silence is data loss nobody noticed.

Cost

The workspace costs nothing to own — you pay for ingestion and for retention beyond the included 30 days. This week ingested under 1 MB, so the measured cost is $0.00.

That is the honest number, and it is also the point: at lab volume none of this matters. The design matters at production volume, which is why the week measures the ratio — 80% dropped, a 46× spread between plans — rather than a dollar figure that would be meaningless at this scale.

Troubleshooting and Lessons

A plan cannot be set on a table that does not exist yet.

  • Problem: putting AzureDiagnostics on the Basic plan returned ResourceNotFound, and the collection rule then failed with a bare InvalidPayload.
  • Root cause: a new workspace has no built-in tables. They materialise when data of that type first arrives — which is after the point you would want the cheap plan already in place.
  • Resolution: custom tables, created with azapi, because azurerm_log_analytics_workspace_table has nowhere to put a schema.
  • Lesson learned: cost controls that depend on a resource existing cannot be applied to resources Azure creates on demand. Create the table yourself and the plan is yours to set from the start.

Ingestion returns 403 until RBAC propagates.

  • Problem: posting to the ingestion endpoint returned 403 immediately after a successful apply.
  • Root cause: posting needs Monitoring Metrics Publisher on the DCR, and granting a role is not instant.
  • Resolution: retry. Measured: ten attempts over five minutes, then 204.
  • Lesson learned: a 403 straight after a role assignment is a clock, not a misconfiguration. Validation has to retry or it reports a correct deployment as broken.

The cap had no alarm, and the check said it did.

  • Problem: the validation passed while the daily cap could still trip in total silence.
  • Root cause: the test counted action groups. An action group is a destination; nothing fires it without a rule, and there was no rule.
  • Resolution: assert on an enabled query rule wired to an action group, which is the thing that actually sends the mail.
  • Lesson learned: a mailbox is not a smoke detector. A check that goes green while the thing it verifies is missing is worse than no check, because it stops anyone looking.

Cleanup and Key Takeaways

Cleanup

This week stays up. Weeks 9 and 10 send their data here and an idle workspace costs nothing, so cleanup.sh refuses without --force.

When it does run, the workspace is soft-deleted for 14 days and its name stays reserved — so rebuilding inside that window fails on a name conflict unless you recover it rather than create a new one.

References

Key takeaways

  • Filter at ingest, not with a cap. A cap stops collection after the money is spent; a transformation means the rows never arrive.
  • Pick the plan by how the data is queried. Analytics is free to query; Basic and Auxiliary bill per GB scanned. Cheap to ingest and cheap to use are different properties.
  • Set the table plan before data arrives — if you can. Built-in tables do not exist until their first row does.
  • An action group is not an alarm. Without a rule firing it, nothing happens and nobody is told.

Comments

How was your experience?
Your feedback helps improve this site.
PoorExcellent