resourceId

Synopsis

Returns the unique identifier of a resource.

Syntax

resourceId('<resourceTypeName>', '<instanceName>')

Description

The resourceId() function returns a handle to a specific resource instance in the configuration. This function enables instances to reference another instance for the dependsOn option.

Note

When using the resourceId function for nested resource instances, instances can only reference other instances in the same resource provider or group instance. They can't use the resourceId() function to lookup instances at the top-level of the configuration document or inside another provider or group instance.

Examples

Example 1 - Reference a resource as a dependency

The following configuration uses the resourceId() function to reference the instance named Tailspin Key as a dependency of the Update Tailspin Automatically resource instance.

# resourceId.example.1.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
  - name: Tailspin Key
    type: Microsoft.Windows/Registry
    properties:
      keyPath: HKCU\tailspin
      _ensure: Present
  - name: Update Tailspin Automatically
    type: Microsoft.Windows/Registry
    properties:
      keyPath:   HKCU\tailspin\updates
      valueName: automatic
      valueData:
        String: enable
    dependsOn:
      - "[resourceId('Microsoft.Windows/Registry', 'Tailspin Key')]"

Example 2 - Reference a group resource as a dependency

The following configuration uses the resourceId() function to specify the DSC/AssertionGroup resource instance named 'IsWindows' as a dependency of the Example Key resource instance.

# resourceId.example.2.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
  - name: IsWindows
    type: DSC/AssertionGroup
    properties:
      $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
      resources:
        - name: os
          type: Microsoft/OSInfo
          properties:
            family: Windows
  - name: Example Key
    type: Microsoft.Windows/Registry
    properties:
      keyPath: HKCU\example
      _exist: true

Parameters

resourceTypeName

The value of the type property of the resource instance to reference. The value must be the fully qualified type name for the resource.

Type:     string
Required: true
Position: 0

instanceName

The value of the name property of the resource instance to reference.

Type:     string
Required: true
Position: 0