二头肌字符串数组

Bicep String Arrays

我正在尝试部署部分资源,如 Microsoft 所示:

resource symbolicname 'Microsoft.OperationsManagement/solutions@2015-11-01-preview' = {
  name: 'string'
  location: 'string'
  tags: {
    tagName1: 'tagValue1'
    tagName2: 'tagValue2'
  }
  plan: {
    name: 'string'
    product: 'string'
    promotionCode: 'string'
    publisher: 'string'
  }
  properties: {
    containedResources: [
      'string'
    ]
    referencedResources: [
      'string'
    ]
    workspaceResourceId: 'string'
  }
}

让我头疼的问题是referencedResources: ['string']

在我们的 CICD 过程中,我们为每个环境(开发、测试、生产)使用 json 个文件作为可配置值,这个元素工作正常并且经过了反复测试,但是当我尝试实施时它失败了referencedResources

的字符串数组

JSON 配置片段(我目前尝试了很多):

"operationsManagement": {
    "value": [
        {
            "name": "SQLAdvancedThreatProtection(uksdevmonsa-log)",
            "resourceGroup": "uks-dev-monitor-rg",
            "product": "OMSGallery/SQLAdvancedThreatProtection",
            "containedResources": [""],
            "location": "uksouth"
        },
        {
            "name": "SQLVulnerabilityAssessment(uksdevmonsa-log)",
            "resourceGroup": "uks-dev-helix-monitor-rg",
            "product": "OMSGallery/SQLVulnerabilityAssessment",
            "containedResources": ["SQLVulnerabilityAssessment(uksdevmonsa-log)"],
            "location": "uksouth"
        },
        {
            "name": "SQLAuditing(uksdevmonsa-log)",
            "resourceGroup": "uks-dev-monitor-rg",
            "product": "SQLAuditing",
            "containedResources": ["SQLSecurityInsights", "SQLAccessToSensitiveData"],
            "location": "uksouth"
        }
    ]
} 

二头肌是如何实现的:

resource opManagement 'Microsoft.OperationsManagement/solutions@2015-11-01-preview' = [for (manage, i) in operationsManagement: {
  dependsOn: [
    insights
  ]
  name: manage.Name
  tags: tags
  location: manage.location
  plan: {
    name: manage.Name
    promotionCode: ''
    product: manage.product
    publisher: 'Microsoft'
  }
  properties: {
    containedResources: manage.containedResources
    workspaceResourceId: insights[i].id
  }
}]

operationsManagement 是 Bicep 参数数组,通过 YAML 任务 Azure CLI

加载了 JSON 配置的全部内容(以上只是一个片段)

错误信息:

"Unable to process template language expressions for resource 
'/subscriptions/123/resourceGroups/uks-dev-monitor-rg/providers/Microsoft.OperationsManagement/solutions/SQLAuditing(sql-log)' at line '57' and column '5'. 
'The language expression property array index '2' is out of bounds.

错误是“越界”——二头肌片段中唯一引用数组的地方是 workspaceResourceId 属性。

workspaceResourceId: insights[i].id

那是在查看 insights 数组,而不是您的管理对象。所以你在不同的数组上使用循环索引 - 如果它们的大小不一样,你最终会 运行 进入那个。