Service ↔ Azure Resource Model¶
This page is the in-repo source of truth for how a Forge service (a logical group of
per-environment Entra ID application registrations) maps to the live Azure resources that
run it. It exists so that any CLI feature reading deployed or runtime state — service describe
image tags, logs, health, cost, restart, config-drift, and so on — can be built against
documented, verified facts instead of reverse-engineered guesses.
Read this before building an Azure-touching feature
Several of the facts below are not derivable from this repository alone (per-environment
subscription IDs and the CLI's Azure scopes live in cloud-foundations). They were verified
against live Azure with az / Azure Resource Graph. The closing
Authoring Azure-touching features checklist captures
what a new feature or issue must state up front.
🧭 The big picture¶
flowchart TD
R["Repository<br/>(exact-name lookup)"]
S["Service<br/>(common key)"]
subgraph envs["Per environment"]
A["Entra app registration<br/>displayName = {projectId}-{env}"]
W["Azure App Service<br/>name = displayName (1:1)"]
SL["0..N deployment slots<br/>(e.g. pr-10028)"]
end
R -. correlated .-> S
S -->|"one facet per env<br/>(test, qa, uat, prod, ...)"| A
A -->|"identical name"| W
W --> SL
W -. "lives in" .-> SUB["Subscription<br/>(one per environment)"]
A service is not a single Azure resource. It is a key (payments) under which one
application registration — and one App Service — exists per environment, and each
environment lives in a different subscription.
🏷️ The naming invariant (1:1)¶
The Azure App Service name is byte-identical to the Entra application-registration display name. There is no transformation, abbreviation, or reconstruction step between the two.
| Plane | Value (example) |
|---|---|
Entra app-registration displayName |
pol-api-exp-policyportal-test |
| Azure App Service name | pol-api-exp-policyportal-test |
The display name follows the platform project-id convention plus an environment suffix:
{domain}-{app type}[-{app sub type}]-{app name}-{env}
└────────────── projectId ──────────────┘ └─ env ─┘
{domain}-{app type}[-{app sub type}]-{app name}is theprojectId(e.g.pol-api-exp-policyportal). Seesaif service describe→ repository correlation for the same{domain}-{app type}{-app sub type}-{app name}shape.{env}is a recognized environment suffix (see below).
Do not reconstruct or short-form the name
The name is identical across environments apart from the suffix — verified byte-for-byte
across prod, qa, test, and uat. Do not short-form the environment
(e.g. prod → prd) and do not rebuild the name from projectId + env with custom
casing. Take the app-registration displayName and use it verbatim as the App Service
name. Building it any other way is the exact mistake that produced an incorrect
implementation sketch in earlier work.
Environment suffixes¶
Only names ending in a known platform environment suffix are service facets. The
authoritative list lives in
ServiceGrouper
(SAIF.Platform.Sdk.Catalog.ServiceGrouper) and is matched longest-suffix-first:
platformdev, prod, test, uat, qa
A registration without one of these suffixes (a free-text or vendor app registration) is not a platform service and is excluded from grouping rather than mapped to a synthetic environment.
🌍 Environment → subscription topology¶
Each environment of a service runs in a different Azure subscription. For a single service,
expect a distinct subscription GUID per environment (verified: four distinct subscriptions for
prod / qa / test / uat).
There is no in-repo environment → subscription map
The per-environment subscription IDs are owned by cloud-foundations, not this
repository. Do not hardcode a subscription map and do not assume a discoverable
env → subscription → resource group mapping exists here — it does not.
Discovery strategy: Azure Resource Graph, by exact name¶
Because the naming invariant guarantees a globally unique, exact App Service name, the supported way to locate a service's resources is an Azure Resource Graph (ARG) query by exact name across all subscriptions the caller can see — never a hardcoded subscription/resource-group map.
Resources
| where type =~ 'microsoft.web/sites'
| where name =~ 'pol-api-exp-policyportal-test'
| project name, resourceGroup, subscriptionId, location, tags, properties.siteConfig.linuxFxVersion
This automatically spans the per-environment subscriptions without the CLI knowing which subscription an environment maps to, and it degrades gracefully: a subscription the caller cannot read simply returns no row instead of failing the whole query.
🗂️ The catalog data model (lossy by design)¶
The service catalog is built in two stages, and the second stage discards information the first stage read. Knowing this prevents you from expecting the App Service name to be available downstream when it is not.
| Stage | Type | Keeps | Discards |
|---|---|---|---|
| Read | EntraServiceCatalogProvider |
Full app-registration displayName, appId, identifierUris |
— |
| Group | ServiceGrouper.Group |
Common key, environment suffix, AppId, identifier URI (per env) |
The full display name / base name detail |
The consequence: after grouping, the catalog knows a service's key and per-environment AppId,
but not the literal App Service name. A feature that needs the App Service name must either
reconstruct it from the catalog key + environment suffix (which reproduces the
naming invariant exactly), or re-read the source app registration.
Prefer re-reading the registration displayName when accuracy matters — it is the invariant's
authoritative side.
🔖 The resource tag contract¶
Resource tags carry stable ownership and governance attributes only. Deployed-version information comes from the App Service site config (linuxFxVersion) and from Azure DevOps build history, not from tags.
Stable tags¶
Forge modules build resource tags from module.environment.context.tags in the saif-resources environment module. Tag keys use lowercase snake_case, which matches the iac-azure-modules convention and the Cloud Adoption Framework advice to use lowercase tag names. These keys stay on every taggable resource and do not change between runs:
| Tag | Value |
|---|---|
managed_by |
"Terraform" |
owner |
The service owner, unless the caller passes its own owner tag |
Repos generated from older templates pass the owning team as a team_name tag, and older callers pass TeamName or ManagedBy. The environment module matches those keys case-insensitively and re-emits the value under owner or managed_by, so resources never carry both spellings. If a caller passes both a canonical key (owner or managed_by) and a legacy alias, the canonical key's value wins.
Azure resources do not inherit tags from their resource group (Microsoft Learn: Use tags to organize your Azure resources), so Forge modules pass context.tags to each resource explicitly.
Since iac-azure-modules 5.3.2 (saif-corp/iac-azure-modules#90), the resource_group module emits the same keys on resource groups: owner from its required team_name input and managed_by = "Terraform". It no longer writes TeamName or DeployedBy. The module keeps a deployed_by input for compatibility but ignores it, and Forge doesn't pass it. Other iac-azure-modules resources use snake_case keys too (managed_by, plus owner, environment, and module on webapp_linux), and no module writes a CreatedDate tag anymore.
One-time tag rename on upgrade
The first apply after moving to iac-azure-modules 5.3.2 updates existing resources in place. TeamName becomes owner. ManagedBy is renamed to managed_by, and DeployedBy on resource groups is dropped. CreatedDate is removed with no replacement.
Azure tag keys are case-insensitive, but ManagedBy and managed_by differ by the underscore, so they are different keys. Update any Azure Policy, cost report, or KQL query that reads the old keys to use owner and managed_by.
No per-run tags¶
Forge modules no longer write a build_number or deployed_by tag. The environment module strips the caller keys build_number, BuildNumber, deployed_by, and DeployedBy (case-insensitive) from the tags input before it builds context.tags. Templates such as src/templates/saif-feature-api/infra/api/app.generated.tf no longer put either key in common_tags, and they keep the deployed_by and build_number variables only as deprecated inputs so existing pipelines that pass them keep working. Repos generated from older templates still pass both keys, and the environment module drops them.
Per-run values caused an in-place tag update on every taggable resource on every apply, which added plan noise and hid real drift. The Cloud Adoption Framework resource tagging guidance frames tags as stable functional, classification, accounting, and ownership attributes. CAF does not explicitly prohibit build-number tags, but a value that changes on every run does not fit those categories.
Older deployments may still carry a build tag
Resources deployed before this change may still carry build_number or BuildNumber. The next apply removes it. Do not treat the tag as current or authoritative, and do not rely on its presence. saif service describe reports BuildNumber as null once the tag is gone.
linuxFxVersion (the deployed image)¶
The deployed container image is read from the site config, not a tag:
Parse the :{tag} portion for the image tag. This is the most reliable per-plane (site and
slot) source of "what is actually running", because every slot has its own linuxFxVersion. Treat it as the authoritative version source for sites and slots.
🧩 Deployment slots¶
App Service deployment slots are zero-or-more and arbitrarily named — not a single fixed "staging" slot.
- A service may have no slots, or several.
- Slot names are feature-driven. PR-preview slots are named
pr-{number}(e.g.pr-10028); see PR slot deployments. - Each slot has its own image (
linuxFxVersion) and therefore its own deployed version. - Slots carry no build tag. Read each slot's version from its own
linuxFxVersion.
A feature that reports deployed state must enumerate slots dynamically and read each slot's
linuxFxVersion independently, rather than assuming one well-known slot.
🔐 Azure-read prerequisite (not in place today)¶
The CLI has no Azure Resource Manager awareness today, and the CLI's own application registration lacks the scope required to read ARM/ARG on the user's behalf:
- Required: the delegated Azure Service Management
user_impersonationscope (https://management.azure.com/user_impersonation) on the CLI app registration, plus tenant admin consent. - This is an infrastructure change in
cloud-foundations, not a code change in this repo.
Distinct from a service's own API scope
This Azure Service Management user_impersonation is not the same as the per-service
api://{projectId}-{env}/user_impersonation scope described in
How Authentication Works. The former authorizes calls to
Azure Resource Manager; the latter authorizes calls to a Forge API. A feature needing live
Azure reads depends on the former and must treat it as a prerequisite, not an assumption.
✅ Authoring Azure-touching features¶
Any Forge feature or CLI command that reads or operates on live Azure resources should state,
up front, how it handles each of the following — and verify the assumptions against live Azure
(az / Azure Resource Graph) before finalizing:
- Naming invariant(s) it relies on — and that it uses the app-registration
displayNameverbatim as the App Service name (no short-forming, no reconstruction with custom casing). - Discovery strategy — default to ARG by exact name across visible subscriptions; do
not hardcode an
env → subscription → resource groupmap. - Required Azure scopes / app-registration changes and where they live — e.g. the
Azure Service Management
user_impersonationscope and per-environment subscription IDs are owned bycloud-foundations, not this repo. - Tag contract assumptions: read version from
linuxFxVersionfor sites and slots, not from tags. Forge modules no longer writebuild_number; if an older deployment still carriesbuild_numberorBuildNumber, treat it as stale and read it case-insensitively. - Slot handling — enumerate zero-or-more arbitrarily named slots; never assume a single
stagingslot. - Best-effort degradation — a failure for one environment/subscription (no access, no resource, transient error) must not sink the whole view; surface per-environment status and keep going.
🔗 Related¶
| Topic | Link |
|---|---|
saif service search / describe |
CLI workflows |
| Token acquisition and scopes | How Authentication Works |
| Environment flow and approvers | Environments and Promotion |
| PR-preview deployment slots | PR Slot Deployments |