Pull a row from an array and convert the values to string #17619
Answered
by
johnlokerse
Alastair-Bailey
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
johnlokerse
Jul 21, 2025
Replies: 1 comment 1 reply
-
@Alastair-Bailey filter() to the rescue! With filter() you can do custom filtering of arrays. In your case, you can filter In the Bicep below, you see how to filter the array and set a variable for each value from the object. The targetScope = 'subscription'
@allowed([
'UKCH'
'SGSG'
'USPT'
])
param SiteCode string = 'SGSG'
param DeploymentDate string = utcNow('y')
param SiteDetails array = [
{ Code: 'UKCH', VNETRange: '10.0.1.0/24', Region: 'EMEA', DataCenter: 'NE', Location: 'northeurope' }
{ Code: 'SGSG', VNETRange: '10.0.2.0/24', Region: 'APAC', DataCenter: 'SEA', Location: 'southeastasia' }
{ Code: 'USPT', VNETRange: '10.0.3.0/24', Region: 'AMER', DataCenter: 'EUS2', Location: 'eastus2' }
]
var filteredDetails = first(filter(SiteDetails, details => details.Code == SiteCode))
var code = filteredDetails.Code
var vnetRange = filteredDetails.VNETRange
var region = filteredDetails.Region
var datacenter = filteredDetails.DataCenter
var loc = filteredDetails.Location
resource ConnectionResourceGroup 'Microsoft.Resources/resourceGroups@2025-04-01' = [
for Entry in SiteDetails: if (Entry.Code == SiteCode) {
location: Entry.Location
name: '${Entry.Code}_${Entry.Region}_${Entry.DataCenter}-Connection'
tags: {
Environment: 'IaaS / PaaS'
Application: 'Site Network / Security'
LocationValue: Entry.Code
'Cost Center': 'Site'
Notification: 'SiteIT.Admin.Notifications.${Entry.Code}@company.com'
Creation: DeploymentDate
}
}
] Screenshot of the output variables: ![]() |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Alastair-Bailey
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Alastair-Bailey filter() to the rescue! With filter() you can do custom filtering of arrays. In your case, you can filter
SiteDetails
based onSiteCode
and retrieve that one item from the array.In the Bicep below, you see how to filter the array and set a variable for each value from the object. The
first()
is used to get the first item from the array. This is becausefilter()
returns an array.