Raymondo
Raymondo

Reputation: 587

Bicep String Arrays

I am trying to deploy out part of resource and as shown from 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'
  }
}

The element in question that is causing me a few headaches is referencedResources: ['string']

In our CICD process, we use json files per environment (dev, test, prod) for configurable values and this element works fine and is tried and tested, but it falls over when I try to implement a string array for referencedResources

JSON Config snippet (my current attempt of many):

"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"
        }
    ]
} 

And how the Bicep is implemented:

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 is Bicep parameter array that is loaded with the full contents of the JSON Config (above is just a snippet) via a YAML task Azure CLI

The error message:

"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.

Upvotes: 0

Views: 3290

Answers (1)

bmoore-msft
bmoore-msft

Reputation: 8737

the error is "out of bounds" - the only place in the bicep snippet where you're referencing an array is on the workspaceResourceId property.

workspaceResourceId: insights[i].id

That's looking at the insights array, not your manage object. So you're using an index for a loop on a different array there - and if they are not the same size, you'll run into that eventually.

Upvotes: 1

Related Questions