Created
November 26, 2025 19:03
-
-
Save JKerens/433abf9169c28fe81381ed0703f89e99 to your computer and use it in GitHub Desktop.
Mutating Array w/ Spread Operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| ] | |
| } | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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 | |
| } | |
| })) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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