📋 In This Post
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.
| Difficulty | Advanced — custom tables and ingest-time transformations, and two of the steps are only reachable through azapi |
| Time to complete | One to two hours. Part of it is unavoidable waiting: the role assignment took five minutes to propagate before ingestion stopped returning 403 |
| Deployment method | Terraform (azurerm + azapi), state in HCP Terraform, local execution |
| Source and lab guide | week-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
| Service | Purpose here | What 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
Prerequisites
- Permissions: Contributor and User
Access Administrator on the subscription. The second is not
optional here — the lab grants
Monitoring Metrics Publisheron the data collection rule, and Contributor cannot create role assignments. - A mailbox you can receive at.
alert_emailis a required variable with no default, because a daily cap that trips silently is data loss. It lives interraform.tfvars, which is gitignored. - Terraform ≥ 1.10, with
azurerm5.x andazapi2.x.azapiis not optional:azurerm_log_analytics_workspace_tablehas nowhere to put a schema, so the two custom tables have to be created through ARM directly. - Two resource providers on the subscription —
Microsoft.OperationalInsightsandMicrosoft.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.
azapi tables and the role assignment
both made it in.2. The Terraform
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:
| Plan | Per GB ingested | Queries | Interactive window |
|---|---|---|---|
| Analytics | $2.76 | free to run | up to 2 years |
| Basic | $0.60 | bill per GB scanned | fixed 30 days |
| Auxiliary / Lake | $0.06 | bill per GB scanned | full 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
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'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.
| Test | Expected | Actual | Status |
|---|---|---|---|
| Workspace pricing and cap | PerGB2018 with a daily cap set | pay-as-you-go, cap set | PASS |
| Table plans | PlatformLogs_CL on Analytics, PlatformVerbose_CL on Basic | both on their intended plans | PASS |
| Collection endpoint and rule | both resolve | both resolved | PASS |
| Ingestion accepted | HTTP 204 | 204 | PASS |
| Transformation drops rows before billing | only Warning and above stored — 20 of the 100 sent | 20 stored, 80 dropped at ingest and never billed | PASS |
| The cap has an alarm that fires | an enabled query rule wired to an action group | enabled rule, attached | PASS |
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
AzureDiagnosticson the Basic plan returnedResourceNotFound, and the collection rule then failed with a bareInvalidPayload. - 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, becauseazurerm_log_analytics_workspace_tablehas 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 Publisheron 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
- Configure a table plan in a Log Analytics workspace
- Azure Monitor Logs cost calculations and options
- Set a daily cap on a Log Analytics workspace
- Well-Architected: Log Analytics
- Week 8 code in the lab repository
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