Chapter 3 · Shared pipeline templates
Shared Azure DevOps Pipeline Templates
What it is
A single azuredevops-pipeline-templates repo holds every reusable
pipeline in the platform. A consuming repo's .azuredevops/pipeline.yaml
is a short extends: block: which template, which tag, and the repo's own
settings. The steps live in one place.
| Template | Used by |
|---|---|
terraform_azure |
The landing zone, shared-services and workload infra repos: plan on branches, apply on main, optional architecture diagrams after the apply |
terraform_ado |
Azure DevOps managed as code |
terraform_module_registry |
Every module in the private registry |
ci_cd, python_ci, azure_webapp_cd, azure_functionapp_cd |
Application builds and deploys, including this site |
azure_devops_governance |
Debug output and the "is there a newer tag?" check the Terraform and app templates run |
Why it exists
At work our team moved to shared templates for the same reason we moved
to modules: fix something once instead of in every repo. The risk with
shared templates is that one change can break every pipeline that uses
them at the same time. So nobody consumes a template from main. Each
template has its own version tag, and a repo points at a specific tag.
When a template changes, consumers keep running on the tag they had until
they choose to move, and every run warns them when a newer version is
out, so nobody falls behind without knowing it.
Key decisions
- Every template is versioned on its own. A tag is
<template>-<version>, such asterraform_azure-1.2.1. The templates repo has its own validation pipeline. It follows each template's- template:references recursively, so a change to a shared task file counts as a change to every template that includes it, and it fails on a template path that doesn't exist. A template that changed needs a newCHANGELOG.mdentry with a version that isn't tagged yet, and the merge tomaincreates the tag. A fix to the Terraform template doesn't force every app pipeline to move. - Consumers pin a tag, and are told when they fall behind. Every run of the Terraform, Azure DevOps, Python CI and app deploy templates reads the template tags it was built from and compares each one with the newest tag in the templates repo. If there's a newer one, the run shows a warning naming it. Nothing fails, and upgrading stays a deliberate change in the consumer's own pull request.
- Only what changed gets planned or applied. The Terraform template
takes a list of workspaces, each with one or more regions, and compares
the commit with
main(onmain, with the previous commit) to find which ones changed. A pull request plans those; the merge applies them inside an Azure DevOps environment, so its approval and branch checks apply. - One identity per region. Each region names its own service connection and subscription, used for init, plan and apply. The connections use workload identity federation, so no pipeline holds an Azure secret.
- New features are opt-in. The diagram stage arrived in a minor version and does nothing until a region turns it on, so upgrading the tag is safe even for a repo that doesn't want it.
- Built for my own agents. The pipelines run on a self-hosted ARM64 agent pool, where the standard Python setup task can't download Python. The Python template can install it natively instead, which is one flag for a consumer rather than a workaround in every repo.
Current state
Every Terraform, module and application repo in the platform runs on
these templates. terraform_azure is on 1.2.1, used by the landing zone,
shared-services and workload repos; this site builds and deploys with
ci_cd, running flake8 and its unit tests before an approval-gated deploy
to its App Service.