Resource class

Base class for all Azure resources.

Example

import { ResourceGroup, Stack } from "@azure/provisioning-core";
import { KeyVault } from "@azure/provisioning-keyvault";

const stack = new Stack("my-app", { targetScope: "subscription" });
const rg = new ResourceGroup(stack, { name: "rg-my-app", location: "eastus" });
const vault = new KeyVault(rg, {
  name: "kv-my-app",
  properties: {
    tenantId: "11111111-1111-1111-1111-111111111111",
    sku: { family: "A", name: "standard" },
  },
});

// vault.name is an Expression, not a string
// vault.id compiles to resourceId(...)
Extends

Remarks

Resources are fully initialized at construction time. Pass a parent ProvisioningComponent (typically a Stack or ResourceGroup) as the first argument — the resource registers itself in the tree automatically.

Properties use expression-backed proxies: reading resource.name returns an Expression that compiles to a Bicep symbolic reference, not a plain string. Use this.expr() in subclasses to create property getters and this.setProperty() for setters.

Properties

apiVersion
condition
dependsOn
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.

existing
id
name

The Azure resource name as a Bicep symbolic-reference expression.

The value is established at construction time (either user-supplied via props.name or filled in by the naming policy) and stored on state.name. The setter routes through setProperty so post- construction edits flow through the same proxy/expression machinery as any other property — useful when working with a base Resource reference and re-binding the name dynamically. Singleton subclasses override this getter to narrow the return type to the literal Expression<"<singletonName>">; non-singleton subclasses inherit this accessor pair as-is.

self

Public identity for this node.

type
[RESOURCE_BRAND]

Brand marker for cross-realm isResource() checks. Uses Symbol.for so it survives multiple copies of @azure/provisioning-core.

Inherited Properties

children
parent
[RESOURCE_DECLARATION_BRAND]

Brand marker for cross-realm isResourceDeclaration() checks. Uses Symbol.for so it survives multiple copies of @azure/provisioning-core. Inherited by every resource declaration implementation.

Methods

registerShape({ apiVersion: string, resourceType: string }, FlatModelShape, FlatVariantSelector)

Register a FlatModelShape for this resource class's (resourceType, apiVersion) pair. Intended to be invoked from a static {} initializer in generated subclasses so the registration happens at module load.

The static method reads resourceType and apiVersion off this (the subclass that called it), so callers don't repeat the literals.

Inherited Methods

isChildOf(ProvisioningComponent)
transform((component: ProvisioningComponent) => void)

Applies a callback to every descendant component/resource that matches the given constructor, including this when it matches.

transform<TComponent>(ProvisioningComponentConstructor<TComponent>, (component: TComponent) => void)
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.

Constructor Details

Resource<TType>(ProvisioningComponent, ResourceProps<TType> & Record<string, unknown>, ResourceOptions)

new Resource(context: ProvisioningComponent, props: ResourceProps<TType> & Record<string, unknown>, options?: ResourceOptions)

Parameters

props

ResourceProps<TType> & Record<string, unknown>

options
ResourceOptions

Property Details

apiVersion

string apiVersion

Property Value

string

condition

ExpressionOrValue<boolean> | undefined condition

Property Value

ExpressionOrValue<boolean> | undefined

dependsOn

(readonly ResourceDeclaration<string>[]) | undefined dependsOn

Property Value

(readonly ResourceDeclaration<string>[]) | undefined

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

existing

boolean | undefined existing

Property Value

boolean | undefined

id

Expression<string> id

Property Value

Expression<string>

name

The Azure resource name as a Bicep symbolic-reference expression.

The value is established at construction time (either user-supplied via props.name or filled in by the naming policy) and stored on state.name. The setter routes through setProperty so post- construction edits flow through the same proxy/expression machinery as any other property — useful when working with a base Resource reference and re-binding the name dynamically. Singleton subclasses override this getter to narrow the return type to the literal Expression<"<singletonName>">; non-singleton subclasses inherit this accessor pair as-is.

Expression<string> name

Property Value

Expression<string>

self

Public identity for this node.

this self

Property Value

this

type

TType type

Property Value

TType

[RESOURCE_BRAND]

Brand marker for cross-realm isResource() checks. Uses Symbol.for so it survives multiple copies of @azure/provisioning-core.

[RESOURCE_BRAND]: true

Property Value

true

Inherited Property Details

children

children: ProvisioningComponent[]

Property Value

Inherited From ResourceDeclaration.children

parent

parent: ProvisioningComponent | undefined

Property Value

ProvisioningComponent | undefined

Inherited From ResourceDeclaration.parent

[RESOURCE_DECLARATION_BRAND]

Brand marker for cross-realm isResourceDeclaration() checks. Uses Symbol.for so it survives multiple copies of @azure/provisioning-core. Inherited by every resource declaration implementation.

[RESOURCE_DECLARATION_BRAND]: true

Property Value

true

Inherited From ResourceDeclaration.[RESOURCE_DECLARATION_BRAND]

Method Details

registerShape({ apiVersion: string, resourceType: string }, FlatModelShape, FlatVariantSelector)

Register a FlatModelShape for this resource class's (resourceType, apiVersion) pair. Intended to be invoked from a static {} initializer in generated subclasses so the registration happens at module load.

The static method reads resourceType and apiVersion off this (the subclass that called it), so callers don't repeat the literals.

static function registerShape(this: { apiVersion: string, resourceType: string }, shape: FlatModelShape, variantSelector?: FlatVariantSelector)

Parameters

this

{ apiVersion: string, resourceType: string }

variantSelector
FlatVariantSelector

Inherited Method Details

isChildOf(ProvisioningComponent)

function isChildOf(component: ProvisioningComponent): boolean

Parameters

Returns

boolean

Inherited From ResourceDeclaration.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 ResourceDeclaration.transform

transform<TComponent>(ProvisioningComponentConstructor<TComponent>, (component: TComponent) => void)

function transform<TComponent>(ctor: ProvisioningComponentConstructor<TComponent>, callback: (component: TComponent) => void): this

Parameters

callback

(component: TComponent) => void

Returns

this

Inherited From ResourceDeclaration.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 ResourceDeclaration.visit