Skip to content

Commit cce8fe6

Browse files
committed
Update with parameters
1 parent 659cef4 commit cce8fe6

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

docs/reference/schemas/config/functions/tryIndexFromEnd.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,27 @@ handle missing data gracefully.
8585
Use `tryIndexFromEnd()` to implement flexible backup retention policies that
8686
adapt to available backups without failing when fewer backups exist than
8787
expected. This example retrieves the third-most-recent backup if available. This
88-
example uses [`createArray()`][05] to build the backup timestamps.
88+
example uses [`parameters()`][06] to reference the backup timestamps array.
8989

9090
```yaml
9191
# tryIndexFromEnd.example.2.dsc.config.yaml
9292
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
93+
parameters:
94+
backupTimestamps:
95+
type: array
96+
defaultValue:
97+
- 20250101
98+
- 20250108
99+
- 20250115
100+
- 20250122
101+
- 20250129
93102
resources:
94103
- name: Backup Retention
95104
type: Microsoft.DSC.Debug/Echo
96105
properties:
97106
output:
98-
backups: "[createArray(20250101, 20250108, 20250115, 20250122, 20250129)]"
99-
retainAfter: "[tryIndexFromEnd(createArray(20250101, 20250108, 20250115, 20250122, 20250129), 3)]"
107+
backups: "[parameters('backupTimestamps')]"
108+
retainAfter: "[tryIndexFromEnd(parameters('backupTimestamps'), 3)]"
100109
description: "Retain backups newer than the third-most-recent"
101110
```
102111

@@ -130,22 +139,29 @@ you to implement a retention policy that keeps the three most recent backups.
130139

131140
Use `tryIndexFromEnd()` to access configuration values from arrays of varying
132141
lengths. This is useful when configuration arrays might have different numbers
133-
of elements across environments. This example uses [`createArray()`][05] to
134-
build the log level arrays.
142+
of elements across environments. This example uses [`parameters()`][06] to
143+
reference the log level arrays.
135144

136145
```yaml
137146
# tryIndexFromEnd.example.3.dsc.config.yaml
138147
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
148+
parameters:
149+
productionLevels:
150+
type: array
151+
defaultValue: [ERROR, WARN, INFO]
152+
devLevels:
153+
type: array
154+
defaultValue: [ERROR, WARN, INFO, DEBUG, TRACE]
139155
resources:
140156
- name: Log Configuration
141157
type: Microsoft.DSC.Debug/Echo
142158
properties:
143159
output:
144-
productionLevels: "[createArray('ERROR', 'WARN', 'INFO')]"
145-
devLevels: "[createArray('ERROR', 'WARN', 'INFO', 'DEBUG', 'TRACE')]"
146-
prodThirdLevel: "[tryIndexFromEnd(createArray('ERROR', 'WARN', 'INFO'), 3)]"
147-
devThirdLevel: "[tryIndexFromEnd(createArray('ERROR', 'WARN', 'INFO', 'DEBUG', 'TRACE'), 3)]"
148-
prodFifthLevel: "[tryIndexFromEnd(createArray('ERROR', 'WARN', 'INFO'), 5)]"
160+
productionLevels: "[parameters('productionLevels')]"
161+
devLevels: "[parameters('devLevels')]"
162+
prodThirdLevel: "[tryIndexFromEnd(parameters('productionLevels'), 3)]"
163+
devThirdLevel: "[tryIndexFromEnd(parameters('devLevels'), 3)]"
164+
prodFifthLevel: "[tryIndexFromEnd(parameters('productionLevels'), 5)]"
149165
```
150166

151167
```bash
@@ -184,8 +200,7 @@ appropriate log level or `null` without throwing errors.
184200
Use `tryIndexFromEnd()` with [`coalesce()`][02] to implement fallback logic when
185201
accessing configuration values from arrays that might have different lengths
186202
across regions. This example shows how to safely access regional endpoints with
187-
a default fallback. This example uses [`createArray()`][05] to build the
188-
regional endpoint arrays.
203+
a default fallback.
189204

190205
```yaml
191206
# tryIndexFromEnd.example.4.dsc.config.yaml
@@ -281,6 +296,7 @@ The function returns an error in the following cases:
281296
- [`equals()`][03] - Compares two values for equality
282297
- [`not()`][04] - Inverts a boolean value
283298
- [`createArray()`][05] - Creates an array from provided values
299+
- [`parameters()`][06] - Returns the value of a specified configuration parameter
284300

285301
<!-- Link reference definitions -->
286302
[00]: ./last.md
@@ -289,3 +305,4 @@ The function returns an error in the following cases:
289305
[03]: ./equals.md
290306
[04]: ./not.md
291307
[05]: ./createArray.md
308+
[06]: ./parameters.md

0 commit comments

Comments
 (0)