Skip to content

Use reference() in copy() loop throws not implemented #1286

@Gijsreyn

Description

@Gijsreyn

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Summary

As a configuration author, I want the ability to use the reference() function in copy() loop. However, the current implementation throws an error: Error: Parser: The 'reference()' function cannot be used when processing a 'Copy' loop.

According to the ARM docs, this should be possible.

Steps to reproduce

  1. Create the following configuration document (using DatabricksDsc module):
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
  workspaceUrl:
    type: string
  accessToken:
    type: string
    defaultValue: "[envvar('BEARER_TOKEN')]"
  dabConfiguration:
    type: object
  uamiConfiguration:
    type: object
  clusterConfiguration:
    type: object
  clusterPolicies:
    type: array
    defaultValue:
    - smallClusterPolicy
    - mediumClusterPolicy
    - largeClusterPolicy
resources:
  - name: "[format('{0}', parameters('clusterConfiguration')[parameters('clusterPolicies')[copyIndex()]].name)]"
    copy:
      name: clusterPolicyLoop
      count: "[length(parameters('clusterPolicies'))]"
    type: DatabricksDsc/DatabricksClusterPolicy
    properties:
      WorkspaceUrl: "[parameters('workspaceUrl')]"
      AccessToken: "[parameters('accessToken')]"
      Name: "[parameters('clusterConfiguration')[parameters('clusterPolicies')[copyIndex()]].name]"
      Description: "[parameters('clusterConfiguration')[parameters('clusterPolicies')[copyIndex()]].description]"
      Definition: "[parameters('clusterConfiguration')[parameters('clusterPolicies')[copyIndex()]].definition]"

  - name: "[format('{0} permission', parameters('clusterConfiguration')[parameters('clusterPolicies')[copyIndex()]].name)]"
    copy:
      name: clusterPolicyPermissionLoop
      count: "[length(parameters('clusterPolicies'))]"
    dependsOn:
      - "[resourceId('DatabricksDsc/DatabricksClusterPolicy', parameters('clusterConfiguration')[parameters('clusterPolicies')[copyIndex()]].name)]"
    type: DatabricksDsc/DatabricksClusterPolicyPermission
    properties:
      WorkspaceUrl: "[parameters('workspaceUrl')]"
      AccessToken: "[parameters('accessToken')]"
      ClusterPolicyId: "[reference(resourceId('DatabricksDsc/DatabricksClusterPolicy', parameters('clusterConfiguration')[parameters('clusterPolicies')[copyIndex()]].name)).PolicyId]"
      AccessControlList:
      - ServicePrincipalName: "[parameters('dabConfiguration').servicePrincipalId]"
        PermissionLevel: 'CAN_USE'

Expected behavior

The copy loop works, referencing the earlier created resources.

Actual behavior

Error: Parser: The 'reference()' function cannot be used when processing a 'Copy' loop

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.4
PSEdition                      Core
GitCommitId                    7.5.4
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

dsc 3.2.0-preview.8

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions