Stack class
A Stack defines a deployment unit.
- Extends
Remarks
Each stack produces one or more Bicep files — resources at different scopes (subscription vs. resource group) are split into separate files linked by module references.
Resources register themselves by passing the stack (or a child component)
as their first constructor argument. Stack.add() is available as a
convenience for creating child components with the stack as parent.
The targetScope option controls the Bicep target scope. Default is
"subscription", which requires explicit ResourceGroup instances.
Set "resourceGroup" to deploy resources directly into an existing
resource group.
Every stack registers itself in Stack.roots for collection by tools
like the playground and CLI.
Constructors
| Stack(string, Stack |
Create a root stack. |
Properties
| deployment |
The effective deployment context inherited from ancestors, resolved by walking up the parent chain (this node's own local contribution is intentionally excluded — a node's contribution flows to its descendants, not to itself). Each field is resolved per its own rule:
Returns an object whose fields may all be |
| name | |
| outputs | |
| parameters | |
| roots | All root stacks created since the last call to |
| self | Public identity for this node. |
| target |
|
| variables |
Methods
| add<T>(T, (Constructor |
Create a child under this stack (with the stack as its parent context),
as a convenience for Constructs a single child instance and returns it. |
| clear |
Returns all root stacks and clears the registry. Useful for collecting all stacks after executing user code (e.g. in the playground or CLI). |
| get |
Find the first scalar resource of |
| get |
The scalar resources in this stack. With no By default walks the whole tree; pass |
| get |
Inherited Methods
| is |
|
| transform((component: Provisioning |
Applies a callback to every descendant component/resource that matches the
given constructor, including |
| transform<TComponent>(Provisioning |
|
| visit((component: Provisioning |
Depth-first visit of this node and all descendants.
Return |
Constructor Details
Stack(string, StackOptions)
Create a root stack.
new Stack(name: string, options?: StackOptions)
Parameters
- name
-
string
- options
- StackOptions
Property Details
deploymentContext
The effective deployment context inherited from ancestors, resolved by walking up the parent chain (this node's own local contribution is intentionally excluded — a node's contribution flows to its descendants, not to itself). Each field is resolved per its own rule:
location: nearest ancestor with a value wins.namingPolicy: nearest ancestor with a value wins.tags: flat-merged across all ancestors; innermost wins on key conflict.
Returns an object whose fields may all be undefined if no ancestor
contributed anything.
DeploymentContext deploymentContext
Property Value
name
name: string
Property Value
string
outputs
parameters
roots
All root stacks created since the last call to Stack.clearRoots().
static readonly Stack[] roots
Property Value
readonly Stack[]
self
Public identity for this node.
this self
Property Value
this
targetScope
variables
Inherited Property Details
children
parent
parent: ProvisioningComponent | undefined
Property Value
ProvisioningComponent | undefined
Inherited From ProvisioningComponent.parent
Method Details
add<T>(T, (ConstructorParameters<T> extends [any, Object] ? Rest : never))
Create a child under this stack (with the stack as its parent context),
as a convenience for new Ctor(stack, ...args).
Constructs a single child instance and returns it.
function add<T>(ctor: T, args: (ConstructorParameters<T> extends [any, Object] ? Rest : never)): InstanceType<T>
Parameters
- ctor
-
T
- args
-
(ConstructorParameters<T> extends [any, Object] ? Rest : never)
Returns
InstanceType<T>
clearRoots()
Returns all root stacks and clears the registry. Useful for collecting all stacks after executing user code (e.g. in the playground or CLI).
static function clearRoots(): Stack[]
Returns
Stack[]
getResource<T>(ResourceCtor<T>, string, QueryOptions)
Find the first scalar resource of type whose literal name equals
name, or undefined if none matches.
function getResource<T>(type: ResourceCtor<T>, name: string, options?: QueryOptions): T | undefined
Parameters
- type
-
ResourceCtor<T>
- name
-
string
- options
- QueryOptions
Returns
T | undefined
Remarks
Returns the first match in tree order. ARM names are unique only per
resource type within a scope, so a stack MAY legitimately contain more
than one resource of the same type and name (e.g. across different
resource groups) — this returns whichever is found first. Use
getResources(type) and filter yourself if you need all matches.
Only scalar resources are searched, and names that do not resolve to a
string literal are never matched. Pass { recursive: false } to search
only the stack's direct children.
getResources(QueryOptions)
The scalar resources in this stack. With no type, returns
every scalar resource; pass a resource class to filter and narrow to
that subclass. Returns a plain array — use native .filter / .find /
.map for anything further.
By default walks the whole tree; pass { recursive: false } to consider
only the stack's direct children.
function getResources(options?: QueryOptions): Resource<string>[]
Parameters
- options
- QueryOptions
Returns
Resource<string>[]
getResources<T>(ResourceCtor<T>, QueryOptions)
function getResources<T>(type: ResourceCtor<T>, options?: QueryOptions): T[]
Parameters
- type
-
ResourceCtor<T>
- options
- QueryOptions
Returns
T[]
Inherited Method Details
isChildOf(ProvisioningComponent)
function isChildOf(component: ProvisioningComponent): boolean
Parameters
- component
- ProvisioningComponent
Returns
boolean
Inherited From ProvisioningComponent.isChildOf
transform((component: ProvisioningComponent) => void)
Applies a callback to every descendant component/resource that matches the
given constructor, including this when it matches.
function transform(callback: (component: ProvisioningComponent) => void): this
Parameters
- callback
-
(component: ProvisioningComponent) => void
Returns
this
Inherited From ProvisioningComponent.transform
transform<TComponent>(ProvisioningComponentConstructor<TComponent>, (component: TComponent) => void)
function transform<TComponent>(ctor: ProvisioningComponentConstructor<TComponent>, callback: (component: TComponent) => void): this
Parameters
- ctor
-
ProvisioningComponentConstructor<TComponent>
- callback
-
(component: TComponent) => void
Returns
this
Inherited From ProvisioningComponent.transform
visit((component: ProvisioningComponent) => boolean | void)
Depth-first visit of this node and all descendants.
Return false from the callback to skip visiting that node's children.
function visit(callback: (component: ProvisioningComponent) => boolean | void)
Parameters
- callback
-
(component: ProvisioningComponent) => boolean | void
Inherited From ProvisioningComponent.visit