@@ -88,24 +88,33 @@ for the non-existent `enableAlpha` flag (which `coalesce()` converts to
8888
8989Retrieve environment-specific configuration values with safe defaults. This is
9090useful when different environments might have different configuration keys. This
91- example uses [`createObject ()`][03 ] to build the environment settings and
92- demonstrates accessing nested object properties .
91+ example uses [`parameters ()`][07 ] to reference the environment configuration,
92+ making the complex nested object structure easier to understand .
9393
9494` ` ` yaml
9595# tryGet.example.2.dsc.config.yaml
9696$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
97+ parameters:
98+ environments:
99+ type: object
100+ defaultValue:
101+ production:
102+ replicas: 5
103+ region: us-east-1
104+ staging:
105+ replicas: 2
97106resources:
98107- name: Environment Config
99108 type: Microsoft.DSC.Debug/Echo
100109 properties:
101110 output:
102- environments: "[createObject('production', createObject('replicas', 5, 'region', 'us-east-1'), 'staging', createObject('replicas', 2) )]"
103- productionEnv: "[tryGet(createObject('production', createObject('replicas', 5, 'region', 'us-east-1'), 'staging', createObject('replicas', 2) ), 'production')]"
104- stagingEnv: "[tryGet(createObject('production', createObject('replicas', 5, 'region', 'us-east-1'), 'staging', createObject('replicas', 2) ), 'staging')]"
105- developmentEnv: "[tryGet(createObject('production', createObject('replicas', 5, 'region', 'us-east-1'), 'staging', createObject('replicas', 2) ), 'development')]"
106- prodReplicas: "[tryGet(createObject('replicas', 5, 'region', 'us-east-1 '), 'replicas')]"
107- prodRegion: "[tryGet(createObject('replicas', 5, 'region', 'us-east-1 '), 'region')]"
108- stagingRegion: "[tryGet(createObject('replicas', 2 ), 'region')]"
111+ environments: "[parameters('environments' )]"
112+ productionEnv: "[tryGet(parameters('environments' ), 'production')]"
113+ stagingEnv: "[tryGet(parameters('environments' ), 'staging')]"
114+ developmentEnv: "[tryGet(parameters('environments' ), 'development')]"
115+ prodReplicas: "[tryGet(tryGet(parameters('environments'), 'production '), 'replicas')]"
116+ prodRegion: "[tryGet(tryGet(parameters('environments'), 'production '), 'region')]"
117+ stagingRegion: "[tryGet(tryGet(parameters('environments'), 'staging' ), 'region')]"
109118` ` `
110119
111120` ` ` bash
@@ -301,6 +310,7 @@ The function returns an error in the following cases:
301310- [`equals()`][05] - Compares two values for equality
302311- [`not()`][06] - Inverts a boolean value
303312- [`tryIndexFromEnd()`][01] - Safely retrieves array elements by counting backward from the end
313+ - [`parameters()`][07] - Returns the value of a specified configuration parameter
304314
305315<!-- Link reference definitions -->
306316[00] : ./createArray.md
@@ -310,3 +320,4 @@ The function returns an error in the following cases:
310320[04] : ./if.md
311321[05] : ./equals.md
312322[06] : ./not.md
323+ [07] : ./parameters.md
0 commit comments