ARM deployments
ARM deployments let clients describe Azure resources in one template and apply them at resource-group, subscription, or tenant scope. The deployment system prepares that description, orders the work, sends resource changes through the normal ARM path, and records the result for later inspection. See Core routing and authentication for the request front door, ARM resource governance for shared ARM rules, and Cloud directory configuration for tenant and cloud context.
Deployment surface
Scope model
The deployment surface accepts the ARM Microsoft.Resources/deployments contract at three levels. The level sets the valid resource boundary, the objects available to expressions, and the owner of the deployment record.
| Scope | Main use | Resource boundary |
|---|---|---|
| Resource group | Deploy application resources together | Resources belong to the named resource group |
| Subscription | Create subscription resources such as resource groups or policy | Resource-group resources need a nested deployment |
| Tenant | Create tenant resources or coordinate work across subscriptions | Subscription and resource-group resources need nested deployments |
Subscription- and tenant-scope deployments require a location for the deployment record. A deployment name keeps that location when the record is replaced. A resource-group deployment uses the group's scope and does not need its own location. When expression evaluation needs a resource-group object for a group that is not stored, the object uses the resolved cloud's default location. A cloud-specific default can override the catalog default. Management-group targets are not supported by this deployment surface.
References: src/…/DeploymentsHandler.java• L239-265 src/…/DeploymentsHandler.java• L648-669 src/…/DeploymentEngine.java• L91-130 src/…/DeploymentEngine.java• L471-494 src/…/DeploymentEngine.java• L1141-1153 src/…/CloudDefaults.java• L46-55
Deployment operations
The service exposes the usual deployment record and control actions. A client can create or replace a deployment, read or list its record, validate a template, export the stored template, inspect operations, cancel an active run, or request a what-if result. It also calculates a template hash for clients that need a stable template identity. The deployment record is separate from the resources it creates, so deleting the record does not delete those resources.
The main create flow is asynchronous from the client's view. The create request checks whether the template can run, returns an accepted deployment and a poll URL, and then runs the resource work in the background. The record changes from Accepted to Running and then to Succeeded, Failed, or Canceled. A name cannot be replaced or deleted while its run is active.
This diagram shows how a deployment request becomes a set of ordinary ARM resource operations.
flowchart LR
A[Deployment request] --> B[Read template and links]
B --> C[Resolve parameters and expressions]
C --> D[Build dependency order]
D --> E[Return Accepted]
E --> F[Create resources through ARM]
F --> G[Evaluate outputs]
G --> H[Update deployment record]
References: src/…/DeploymentsHandler.java• L269-346 src/…/DeploymentsHandler.java• L348-361 src/…/DeploymentsHandler.java• L378-389 src/…/DeploymentsHandler.java• L490-585
Template evaluation
Parameters and expressions
Template evaluation turns declared inputs and ARM language expressions into the values sent to resource providers. Parameters can come from the request or from a template default. Each value must match its declared type and any allowedValues; secure values are used during the run but are not returned in the deployment record.
Expressions use the deployment's scope as their context. They can read parameters, variables, deployment metadata, cloud metadata, and the applicable resource-group, subscription, or tenant object. reference() and list*() read live resource state through ARM, so expression evaluation can depend on resources already created or on resources outside the template. Conditional expressions evaluate only the selected branch.
The system also supports resource IDs, string and data functions, array and object functions, copy indexes, date and numeric functions, and user-defined functions. Unsupported functions and invalid values fail validation with InvalidTemplate instead of producing a guessed value.
References: src/…/ParameterValues.java• L25-65 src/…/DeploymentScope.java• L79-121 src/…/DeploymentScope.java• L135-185 src/…/ExpressionEvaluator.java• L20-39 src/…/ExpressionEvaluator.java• L56-129
Resource expansion
The template reader validates the template structure before resource creation. It treats nested child resources as resources with complete parent paths, expands supported copy loops into resource or property values, and evaluates conditions before a resource is sent. Expansion limits prevent a template from growing without bound.
The engine removes template-only fields such as dependsOn, condition, and copy before it sends the resulting resource body. Each resulting resource keeps its own API version and ARM identity, which lets the normal provider handler apply its usual validation and side effects.
References: src/…/DeploymentTemplate.java• L89-104 src/…/DeploymentTemplate.java• L137-195 src/…/CopyLoops.java• L33-79 src/…/DeploymentEngine.java• L684-714
Dependency ordering
Dependency graph
The deployment engine creates resources in an order that satisfies both declared and inferred dependencies. An explicit dependsOn can name a resource by name, type and name, or full ID. A reference() or list*() call creates an implicit dependency when it names a resource by name. A call that uses a full ID does not create that inferred edge because it can refer to an existing resource outside the template.
The graph rejects an unknown dependency, an ambiguous name, or a cycle before any resource is created. A child resource does not depend on its parent unless the template declares that dependency. A dependency on a copy loop applies to its expanded instances.
References: src/…/DependencyGraph.java• L11-26 src/…/DependencyGraph.java• L55-74 src/…/DependencyGraph.java• L120-179 src/…/DeploymentEngine.java• L427-432
Resource execution
After ordering, the engine sends each resource as an internal ARM PUT. This uses the same routing, request governance, and provider handler as a direct client request. Deployment-created state is therefore visible to other ARM services and clients. If a provider returns a long-running response, the engine polls the resource until it reaches a terminal state.
The first resource failure ends the local deployment and records the provider error inside a DeploymentFailed result. Cancellation is checked between resources. It stops further work but keeps resources that were already created. Successful runs evaluate outputs after all required resources finish and record the resource operations and dependency information.
References: src/…/DeploymentEngine.java• L323-380 src/…/DeploymentEngine.java• L646-681 src/…/DeploymentEngine.java• L954-973
Linked and nested templates
Linked content
Linked templates and parameter files let a deployment keep its main request small while storing content at an HTTP or HTTPS URI. The service downloads and validates the linked JSON before planning the deployment, then evaluates it as if it were inline. The original links remain visible in deployment metadata and in the deployment() expression result.
The link must return a JSON object within the download time and size limits. A bad status, invalid content, mismatched contentVersion, unsupported URI, or template spec produces InvalidContentLink or InvalidTemplate. A request cannot provide both inline parameters and a parameters link.
References: src/…/LinkedTemplates.java• L23-37 src/…/LinkedTemplates.java• L70-113 src/…/LinkedTemplates.java• L116-183 src/…/DeploymentsHandler.java• L743-755
Nested deployment scopes
An ARM deployment resource inside a template represents a child deployment. Its resourceGroup and subscriptionId choose a target scope; without them it uses the parent scope. A tenant deployment must name the subscription when it targets a resource group. A nested deployment targeting a management group is rejected.
Nested deployments run as deployments of their target scope and can expose outputs to the parent through reference(). With inner expression scope, the child evaluates its own parameters, variables, and resource names. With the default outer scope, it inherits the parent's evaluated parameters and variables while its deployment and target scope still describe the child deployment. Parent resource references are carried into the child by resource ID when needed.
Relative links in a nested deployment resolve against the parent template's link and keep its query string. This allows a linked template set to share access data without allowing a child path to move the request to another host.
References: src/…/DeploymentEngine.java• L471-494 src/…/DeploymentEngine.java• L717-761 src/…/DeploymentEngine.java• L763-879 src/…/DeploymentTemplate.java• L232-247
What-if results
Change prediction
What-if runs the same preparation and expression evaluation as a deployment but reads current resource state instead of writing it. It compares only the properties the template sets. This keeps provider-generated and read-only fields out of the result. A missing resource is Create; an existing resource is Modify when its desired values differ or NoChange when they do not.
Each change can include the current document, the desired document, and property-level deltas. Tags are compared as a set because a resource PUT replaces the tag set. ResourceIdOnly omits the documents. A nested deployment or a resource whose required expression cannot be evaluated before creation is reported as Unsupported with a reason.
References: src/…/DeploymentEngine.java• L239-305 src/…/WhatIf.java• L18-25 src/…/WhatIf.java• L26-81 src/…/DeploymentsHandler.java• L504-529
Tenant-aware lifecycle
Tenant ownership
Tenant scope gives a deployment a tenant owner even though its URL has no subscription ID. The owner comes from the tenant in the request token when that tenant exists in the directory. Otherwise the default tenant owns the record. This key keeps deployment history from one tenant from being read or replaced by another tenant.
For subscription and resource-group deployments, the tenant comes from the addressed subscription. The same tenant and cloud context supplies the values returned by tenant(), subscription(), and environment(). As a result, resource IDs and cloud metadata remain consistent with the deployment target.
References: src/…/DeploymentsHandler.java• L768-780 src/…/DeploymentEngine.java• L621-642 src/…/DeploymentEngine.java• L1152-1194
Record cleanup
Deployment records are runtime state. A resource-group deployment belongs to its group history, so deleting the group cancels active runs and removes that group's deployment records. Reset also cancels active runs and clears deployment and operation records. The resource state created by a deployment remains governed by the resource and resource-group lifecycle rather than by the deployment record.
References: src/…/DeploymentsHandler.java• L495-502 src/…/DeploymentsHandler.java• L800-821 docs/…/deployments.md• L239-266
Change checklist
When these files or sections are changed, remember to consider these:
- Keep scope validation,
resourceId()behavior, and the resource-group objects—including cloud-specific default locations—aligned. - Keep parameter type checks, secure-value redaction, nested parameter passing, and deployment output echoes aligned.
- Keep explicit dependencies, inferred
reference()andlist*()dependencies, copy-loop expansion, and operation order aligned. - Keep linked-template URI rules, relative-path resolution, query-string forwarding, and echoed link metadata aligned.
- Keep deployment record ownership, tenant selection, group deletion cleanup, and active-run replacement rules aligned.
- Keep what-if comparison rules aligned with the resource bodies that a real deployment sends.
- Keep the deployment action surface and asynchronous status contract aligned when adding or changing actions such as template hashing, validation, or what-if.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A subscription- or tenant-scope deployment omits location | The deployment is rejected with LocationRequired | Scope-aware location validation runs before planning |
| A deployment name is reused with a different location | The replacement is rejected with InvalidDeploymentLocation | The existing record's location is fixed for that name |
| A template has an unknown, ambiguous, or circular dependency | No resource is created and validation returns InvalidTemplate | The dependency graph resolves and checks all edges before execution |
| A linked URI returns bad content or exceeds its limits | The deployment is rejected with a link or template error | Linked content is fetched, bounded, parsed, and version-checked before planning |
| A resource provider rejects one resource | The deployment ends Failed and later resources are not attempted | Each resource result becomes a deployment operation and failure detail |
| A tenant deployment is read with a different caller tenant | The other tenant cannot see or replace the record | Tenant-scope keys include the resolved caller tenant |
| A group is deleted while its deployment is active | The run is canceled and its deployment history is removed | Group cleanup marks the run canceled and removes the group-owned records |
| A client tries to replace or delete an active deployment | The request returns DeploymentActive and the current run continues | The record reserves its name until the run reaches a final state |
Key files
| File | Why to read it |
|---|---|
| src/…/DeploymentsHandler.java | Defines the deployment REST surface, asynchronous record lifecycle, actions, polling, template hashing, and tenant-aware keys |
| src/…/DeploymentEngine.java | Defines template planning, ARM resource execution, nested deployment behavior, outputs, and what-if preparation |
| src/…/DeploymentTemplate.java | Defines the template shape, resource flattening, nested deployments, and structural validation |
| src/…/DeploymentScope.java | Defines the values and live resource reads available to expressions |
| src/…/DependencyGraph.java | Defines explicit and implicit dependency discovery and ordering |
| src/…/LinkedTemplates.java | Defines linked template and parameter-file download and validation |
| src/…/WhatIf.java | Defines property comparison and the projected resource state used by what-if |
| src/…/CloudDefaults.java | Defines the cloud-aware default location used when deployment scope data needs a resource-group location |