Skip to content

Instantly share code, notes, and snippets.

@JKerens
Created November 26, 2025 19:03
Show Gist options
  • Select an option

  • Save JKerens/433abf9169c28fe81381ed0703f89e99 to your computer and use it in GitHub Desktop.

Select an option

Save JKerens/433abf9169c28fe81381ed0703f89e99 to your computer and use it in GitHub Desktop.
Mutating Array w/ Spread Operator
import { overrideMatchValues } from './helpers.bicep
param routingRuleSetsOptions = [
{
name: corRuleSet.name
routingRules: [
{
name: corsRule.name
properties: {
order: corsRule.properties.order
conditions: overrideMatchValues(corsRule.properties.conditions, 'RequestHeader', [
'localhost'
'.mysite.com'
])
actions: corsRule.properties.actions
}
}
nocacheRule
nocache2Rule
]
}
]
@export()
func overrideMatchValues(
conditions resourceInput<'Microsoft.Cdn/profiles/ruleSets/rules@2024-02-01'>.properties.conditions,
conditionName string,
newMatchValues string[]
) resourceOutput<'Microsoft.Cdn/profiles/ruleSets/rules@2024-02-01'>.properties.conditions =>
union(
// keep all the untouched conditions
filter(conditions, c => c.name != conditionName),
// modify the one(s) that match
// !!!BUG - if any new properties are added this will shave off the values
map(
take(
filter(conditions, condition => condition.name == conditionName), 1), c => {
name: c.name
parameters: {
operator: c.parameters.operator
selector: c.parameters.selector
matchValues: newMatchValues
typeName: c.parameters.typeName
negateCondition: c.parameters.negateCondition
}
}))
@export()
func overrideMatchValues(
conditions resourceInput<'Microsoft.Cdn/profiles/ruleSets/rules@2024-02-01'>.properties.conditions,
conditionName string,
newMatchValues string[]
) resourceOutput<'Microsoft.Cdn/profiles/ruleSets/rules@2024-02-01'>.properties.conditions =>
union(
// keep all the untouched conditions
filter(conditions, c => c.name != conditionName),
// modify the one(s) that match
map(
take(
filter(conditions, condition => condition.name == conditionName), 1), c => {
...c
parameters: {
...c.parameters
matchValues: newMatchValues
}
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment