我可以自定义 ARM/BICEP 部署脚本输出的深度吗?

Can I customize the depth of ARM/BICEP Deployment Script Outputs?

我的二头肌模板中有一个部署脚本可以输出一个复杂的对象。当我 运行 脚本时,它工作正常,但我收到有关输出深度的警告。

Resulting JSON is truncated as serialization has exceeded the set depth of 2.

因此,脚本的输出未正确序列化

[{"objectId":"<OBJECT-ID>","tenantId":"<MY-TENANT-ID>","permissions":"System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.List`1[System.String]]"}]

有没有办法自定义部署脚本输出的序列化深度?作为参考,这里是脚本。它获取现有密钥保管库的访问策略列表,并尝试将其保存为脚本输出。

resource getAccessPolicies 'Microsoft.Resources/deploymentScripts@2020-10-01' =  {
  name: '${keyvaultName}_Get_AccessPolicies_Script'
  location: locationName
  identity: {
    type: 'UserAssigned'
    userAssignedIdentities: {
      '${userAssignedIdentityResourceId}': {}
    }
  }
  kind: 'AzurePowerShell'
  properties: {
    arguments: '-keyVaultName ${keyvaultName} -keyvaultResourceGroupName ${resourceGroup().name} -subscriptionId ${subscription().subscriptionId}'
    azPowerShellVersion: '7.2'
    retentionInterval: 'P1D'
    cleanupPreference: 'OnSuccess'
    timeout: 'PT15M'

    scriptContent: '''
      param([string] $keyVaultName, [string] $keyvaultResourceGroupName, [string] $subscriptionId)
      $DeploymentScriptOutputs = @{}
      $DeploymentScriptOutputs['AccessPolicies'] = @()
      $keyVault = Get-AzKeyVault -VaultName $keyVaultName -ResourceGroupName $keyvaultResourceGroupName -SubscriptionId $subscriptionId
      if ($keyVault -eq $null)
      {
        return
      }

      foreach ($policy in $keyVault.AccessPolicies)
      {
        $accessPolicy = @{
          objectId = $policy.ObjectId
          tenantId = $policy.TenantId
          permissions = new-object 'System.Collections.Generic.Dictionary[System.String,System.Collections.Generic.List[System.String]]'
        }
    
        $accessPolicy.permissions["certificates"] = $policy.PermissionsToCertificates.Split(" ")
        $accessPolicy.permissions["keys"] = $policy.PermissionsToKeys.Split(" ")
        $accessPolicy.permissions["secrets"] = $policy.PermissionsToSecrets.Split(" ")
    
        $DeploymentScriptOutputs['AccessPolicies'] += $accessPolicy
      }
      '''
  }
}

深度不可自定义,对于通用解决方案,只需使用字符串而不是哈希 table,请参阅:

https://github.com/Azure/bicep/issues/6438