Home› Blog› Week 3 — The Pin Held. The Default Moved Anyway.
Azure Weekly Lab Azure Terraform

Week 3 — The Pin Held. The Default Moved Anyway.

A version pin protects a caller from a module changing underneath them. It does not protect them from choosing to upgrade — and one of the two breaking changes in this week's 2.0.0 produces no error at all.

Azure Verified Modules HCP Terraform Private Registry Semantic Versioning Azure Storage Terraform
Azure Platform Engineering Lab · Week 3 of 52

Lab Overview

Weeks 1 and 2 built governance: a landing zone with a deny, then policies that repair what they find. Both assumed somebody was creating resources correctly in the first place. This week is about that somebody — the platform team who hands other teams a module and then has to live with every decision baked into it.

Microsoft publishes Azure Verified Modules, and they are good. What they are not is yours. AVM ships a correct storage account; a platform team needs their storage account — the same resource with the arguments already decided, the tag their policy enforces already applied, and diagnostics already wired to the workspace the estate actually reads. The gap between those two is a wrapper module, and the wrapper is the easy part.

The hard part is distribution. Point ten teams at ../../modules/storage-baseline and every one of them is on whatever is in the working tree right now. A relative path has no version. So the question "which version of the storage module is the payments team running" has no answer — not a hard one, no answer — and the day you fix a default, you have changed every consumer simultaneously and told none of them.

A private registry is not a convenience. It is the thing that makes a version pin mean something. Without it, "pinned" is a sentence in a README. With it, a caller writes version = "1.0.0" and gets exactly that content forever — and the interesting question becomes what happens when you publish 2.0.0 next to it.

DifficultyIntermediate — the Terraform is small; the version discipline is the lab
Time to completeAbout an hour, including publishing two module versions to the registry
DeploymentTerraform (azurerm, azapi, random), two stages, HCP Terraform private module registry, local execution
Measured cost$0.00 — two empty storage accounts and a workspace inside the free retention floor
Full lab guideLAB.md — prerequisites, variables, commands, expected outputs, validation and cleanup

Cloud Services and Concepts

ServicePurpose hereWhat it is
Azure Verified Modules The module this lab wraps Microsoft's maintained Terraform modules. Built on the AzAPI provider, which calls Azure's REST API directly rather than going through azurerm.
HCP Terraform private registry Where versions are published and pinned A registry that accepts publishes by API rather than by connecting a repository, which lets one subdirectory of a monorepo publish without being split into its own repo.
Semantic versioning The promise a version number makes A major bump means “this will break you”. The distinction that matters is between a break that fails loudly at plan time and one that applies cleanly and quietly changes behaviour.
Version pin What actually makes a caller safe A module's version must be a literal — not a variable, not a -var flag. Upgrading is therefore a code change and a commit, never a runtime choice.
Storage accounts What the module builds Two of them, one per consumer, differing only by which major version of the module created them.

Architecture and Workflow

Architecture diagram. A module source directory wraps an Azure Verified Module pinned at version 0.10.0. publish.sh runs git archive against a git tag and uploads to an HCP private registry, which holds storage-baseline 1.0.0 and 2.0.0 as immutable versions. One Terraform configuration with one state file then consumes both: module app_a pinned to 1.0.0 creates a storage account with shared keys enabled and no diagnostics, while module app_b pinned to 2.0.0 creates a storage account with shared keys disabled and diagnostics sent to a Log Analytics workspace. Adding app_b changed nothing about app_a.
The whole week on one page. This lab's module wraps an exactly pinned Azure Verified Module, publishes by tag through the registry API, and is consumed twice — once at 1.0.0 and once at 2.0.0.

Three pieces. A wrapper module in the lab's monorepo. A publish script that turns a git tag into a registry version. And a single Terraform configuration holding two consumers of that module, pinned to two different majors — which is not a contrived arrangement, it is the permanent condition of any platform team that owns a module and has no authority to make everyone upgrade on the same day.

The wrapper pins AVM exactly, and that is deliberate asymmetry

In main.tf.

The wrapper pins Azure/avm-res-storage-storageaccount/azurerm at exactly 0.10.0 — not ~> 0.10. That is a different decision from the one a consumer of the wrapper makes, and the reason is that a wrapper's whole job is to be the stable thing. If it floated, a caller pinned to storage-baseline 1.0.0 could still have their storage account change underneath them, which is the exact outcome pinning was supposed to prevent. AVM is also pre-1.0, where semver permits a minor bump to break.

One workspace ID in, two diagnostic settings out

A storage account emits no logs of its own — only the Transaction metric. The read, write and delete audit events belong to the blob service, a separate ARM resource at .../blobServices/default with its own diagnostic setting. Asking for allLogs on the account is accepted and produces nothing, which is the sort of thing discovered during an incident rather than during a deploy. The wrapper takes one workspace ID and creates both settings, so no caller has to know that.

Prerequisites

  • An HCP Terraform organization with a private module registry. This is the one prerequisite that is not Azure at all: the week publishes two versions of a module and then consumes them by version, so a registry you can publish to is the whole exercise.
  • A token that can publish modules — publishing is by tag, through the registry API, not through the UI.
  • Contributor on the subscription. No role assignments are created, so User Access Administrator is not needed.
  • Terraform ≥ 1.10 with azurerm ~> 5.2, plus azapi, random and modtm — the last three arrive transitively through the Azure Verified Module this week wraps, which is itself the point about dependency trees.
  • Three resource providers: Microsoft.Storage, Microsoft.OperationalInsights and Microsoft.Insights.
  • No prior week is required, though the Log Analytics workspace here is this week's own and is not week 08's.

Every variable, both stages and the publish commands are in the lab guide, which is the reproducible half of this write-up.

Implementation

0. How any of this gets deployed

Terraform throughout. State lives in HCP Terraform and the apply runs locally — HCP defaults a new workspace to remote execution, which fails here because no Azure credentials are stored in the workspace.

Nothing below is typed into a terminal by hand. The whole week is six commands, and the order matters more than it looks:

./scripts/publish.sh 1.0.0     # BOTH versions must exist before either stage runs
./scripts/publish.sh 2.0.0
./scripts/deploy.sh v1         # one consumer, pinned to 1.0.0
./scripts/deploy.sh v2         # a second on 2.0.0, alongside the first
./scripts/validate.sh
./scripts/cleanup.sh

count = 0 does not mean "not downloaded". terraform init resolves and installs every module a configuration refers to before it evaluates what any count is — so 2.0.0 has to exist in the registry before stage v1 can initialize at all. That is why both publishes come first.

terraform {
  cloud {
    organization = "Katta"
    workspaces {
      name    = "azure-week-03-dev"
      project = "Azure Platform Lab"
    }
  }
}

The registry itself, read back from the HCP Terraform API rather than described — any reader with a token for their own organization can run the same call and see the same shape:

GET /api/v2/organizations/Katta/registry-modules/private/Katta/storage-baseline/azurerm

module: storage-baseline / azurerm   status: setup_complete
   version 2.0.0 -> ok
   version 1.0.0 -> ok

Two versions, both published, both ok. That is the factory — and this is it in the private registry:

The storage-baseline module in the HCP Terraform private registry, marked Private, provider azurerm, version 2.0.0 selected, with its README and the usage block showing the app.terraform.io source address
Checkpoint: both versions live in the private registry, so a consumer can pin either. A module that exists only on someone's laptop cannot be pinned, which is the problem the registry solves.

1. The module, published from a tag

publish.sh builds the tarball with git archive <tag>:<path> — never from the working tree. A registry version is immutable, so a tarball built from a dirty checkout publishes a version matching no commit, and the only correction available is deleting a version other people may already be pinned to.

2. Two versions, one breaking change of each kind

2.0.0 carries exactly two differences from 1.0.0, chosen to be opposites:

ChangeHow it reaches a caller
Loudlog_analytics_workspace_id becomes requiredMissing required argument, at plan. Nothing deploys
Silentshared_access_key_enabled defaults true → falseNo plan error, no apply error. Whatever authenticated with a shared key stops working at runtime

3. Two consumers, deployed in stages

Stage one creates app_a on 1.0.0. Stage two adds app_b on 2.0.0 beside it and never touches the first block again.

In main.tf.

Azure portal resource group blade showing two storage accounts and a Log Analytics workspace
The two consumers side by side. Identical inputs, different module majors — and from the portal's resource list alone you cannot tell which is which. That is what makes the silent break silent.

The plan for stage two is the evidence, and it is a claim about a plan rather than about a deployment — so the script saves the plan, reports on it, and only then applies:

create   module.app_b[0]...azapi_resource.this
create   module.app_b[0]...containers["data"]
create   module.app_b[0]...diagnostic_setting_blob
create   module.app_b[0]...diagnostic_setting_storage_account

module.app_a changes in this plan: 0

Four resources created, every one of them app_b. A new major landed in the same state file and the consumer pinned to the old one did not move. That is what the pin buys.

Validation and Evidence

A successful apply proves two storage accounts exist. It proves nothing about the thing this week is actually claiming — that a pinned major version protects an existing consumer from a breaking change in a new one. So the checks compare the two consumers against each other rather than against a specification.

TestExpectedActualStatus
Both versions published and usableboth resolve from the registry1.0.0 ok, 2.0.0 okPASS
The baseline the module decidesapplied to both accounts regardless of versionboth TLS1_2, no public blob access, cost-center=platform-labPASS
The 1.0.0 consumer's diagnosticsnone — 1.0.0 allowed the workspace to be omitted0 on the account, 0 on the blob servicePASS
The 2.0.0 consumer's diagnosticstwo, on two different resources1 on the account (Transaction), 1 on the blob service (audit)PASS
The silent breakshared-key access differs between versions1.0.0 True, 2.0.0 FalsePASS
The loud break1.0.0's exact inputs fail against 2.0.0 before planningMissing required argumentPASS
Deployed state matches configurationno driftnonePASS

The two breaks are different animals, and that is the lesson. The loud one stops you at init with a missing argument. The silent one applies cleanly and quietly turns off shared-key access — same inputs, different behaviour, no error. A consumer who skimmed the changelog meets the second one in production.

And adding the new major changed nothing about the old consumer. The stage-v2 plan, read as JSON rather than eyeballed:

module.app_a changes in this plan: 0

Four resources created, all of them module.app_b. That is the property the pin buys — and it is a claim about a plan, which is why deploy.sh saves the plan and reports on it before applying. After the apply, the plan is gone.

Security and Cost

Security

  • The baseline is not optional. TLS 1.2 minimum, HTTPS-only transport, and anonymous blob access disabled are decided in the module, not passed in by callers. A caller cannot forget them because there is no argument to forget.
  • 2.0.0 turns shared keys off by default — the flipped default that makes this week's point also happens to be the more secure posture. A caller who genuinely needs keys can still ask for them, explicitly, in their own code rather than inheriting it.
  • The tag the estate enforces is applied at creation. Every account carries cost-center, so week 2's remediation policy never has to touch anything this module made.
  • Diagnostics reach a workspace — account metrics and blob service audit logs, and in 2.0.0 there is no way to opt out by omission.
  • One honest exception: public_network_access_enabled is true. The alternative is a private endpoint, and a private endpoint without a linked private DNS zone resolves to the public IP and fails in a way that looks like a firewall problem. The zone estate is week 5; the module moves when it exists.

Cost

Two Standard LRS storage accounts and one Log Analytics workspace at PerGB2018 with 30-day retention. Nothing in this week has a per-hour price — no compute, no gateway, no firewall — so the bill is driven entirely by data, and this week stored and ingested essentially none. Pennies while running.

Troubleshooting and Lessons

Both breaking changes are two lines of the module's own variables:

# 1.0.0                          # 2.0.0
variable "log_analytics_workspace_id" {
  type    = string               type = string
  default = null                 # no default - now REQUIRED  (the LOUD break)
}

variable "shared_access_key_enabled" {
  type    = bool                 type = bool
  default = true                 default = false            (the SILENT break)
}

The silent break is only visible on deployed resources.

Both accounts came from the same module, through the same code path, and neither call site mentions shared_access_key_enabled at all. Here is 1.0.0:

Azure portal storage account configuration blade with Allow storage account key access set to Enabled
1.0.0: shared key access Enabled. Nobody asked for this; it is simply what the older major left alone.

And 2.0.0, with every other setting on the blade identical:

Azure portal storage account configuration blade with Allow storage account key access set to Disabled
2.0.0: the same input, Disabled. No error, no warning, no changed argument — the new major decided differently. Anything authenticating with a key stops working on upgrade.

Nothing in either configuration says so. No plan flagged it. This is the half of a major bump that a range constraint hides completely — and a team that writes ~> 2.0 after upgrading has re-armed it for 2.1.0.

An empty module published, and every signal said success.

  • Problem: the first publish uploaded a valid 45-byte tarball containing nothing. The upload returned 200, the version reached status ok, and a consumer would have met the result as a module with no inputs rather than as a failure.
  • Root cause: git archive <tag>:<path> resolves the path relative to the current directory. The script ran from the week directory with a repo-root-relative path, so it did not error — it resolved to an empty tree.
  • Resolution: count the files in the tarball before uploading. The obvious guard does not work: git rev-parse -q --verify "<tag>^{tree}:<path>" still returns a hash for the missed path.
  • Lesson learned: every status in the chain was green because nothing in the chain checked content. A publish pipeline has to assert what it published, not that it published.

A pending version blocks its own retry.

  • Problem: republishing 1.0.0 was refused — "already exists, registry versions are immutable".
  • Root cause: the failed publish created the version record before it broke, leaving it at status pending, awaiting an upload it would never receive.
  • Resolution: delete the version through the API, then republish.
  • Lesson learned: safe here only because nothing was pinned to it yet — which will not be true the second time.

AVM nests deeply enough to hit Windows MAX_PATH.

  • Problem: Filename too long during module download — with core.longpaths=true set and the Windows LongPathsEnabled registry value already 0x1.
  • Root cause: the AVM storage module pulls avm-utl-interfaces once per sub-resource, producing paths like .terraform/modules/app_a.storage_account.queues.role_assignments.interfaces/.git/objects/pack/pack-<sha>.pack.
  • Resolution: move TF_DATA_DIR somewhere short. The module cache is relocatable; the repository's location is not.
  • Lesson learned: when two fixes are both already applied and the error persists, the thing to move is the artefact, not the setting.

A validation that failed on correct resources.

  • Problem: two checks reported failures against resources that were perfectly correct.
  • Root cause: az renders JSON booleans Python-style — True and False, capitalised — and the script compared against lowercase "false".
  • Resolution: normalise case before comparing.
  • Lesson learned: the same shape as a check that passes because its lookup broke, inverted — a check that fails because its comparison did. Both are the check lying about the system.

Cleanup and Key Takeaways

Cleanup

Two kinds of thing were created and only one of them should go. The consumers — a resource group, a workspace, two storage accounts — cost money and prove nothing further, so they are deleted.

The registry versions are kept. They cost nothing, they are the week's actual output, and deleting a published version is the one destructive act a module registry does not forgive: every configuration pinned to it stops initialising, including configurations owned by people who were never asked. The cleanup script takes a --registry flag to remove them and does not do it by default.

References

Key takeaways

  • A relative module path has no version. Every consumer is on HEAD, and "which version is this team running" has no answer. That is the problem a private registry solves, and it is not really about convenience.
  • The pin protects the caller who does nothing. A new major landed in the same state file and the 1.0.0 consumer's plan showed zero changes.
  • The dangerous breaking change is the one that does not break anything. A required input fails loudly at plan and nobody gets hurt. A flipped default applies cleanly and surfaces in production, in whatever was still using the old behaviour.
  • Pin exactly in the module, and exactly in the caller. A range is a standing agreement to skip reading the diff, and the diff is the actual safety mechanism.
  • An immutable registry is unforgiving in both directions. It will not let you fix a bad version, and it will not let you retry a failed publish without deleting what the failure left behind.

Comments

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