Skip to content

Commit 7bf9002

Browse files
(DOCS) Add conceptual documentation
Prior to this change, the docs folder didn't include any conceptual documentation, only reference documents. This change copies existing concept docs into the folder, updates them for GA, and adds new conceptual documentation to make it easier for new users to learn about DSC and start using it.
1 parent fe1f1dd commit 7bf9002

19 files changed

+2956
-0
lines changed
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
---
2+
description: >-
3+
DSC configuration documents are YAML or JSON data files that define the desired state of a system
4+
declaratively. They are used to retrieve, validate, and enforce the state of multiple resource
5+
instances.
6+
ms.date: 03/18/2025
7+
title: DSC configuration documents
8+
---
9+
10+
# DSC configuration documents
11+
12+
<!-- markdownlint-disable MD013 -->
13+
14+
In Microsoft's Desired State Configuration (DSC) platform, DSC configuration documents declare the
15+
desired state of a system as data files. Configuration documents define a collection of
16+
[DSC resource][01] instances to describe what the desired state should be, not how to put the
17+
system into that state. The DSC resources handle the _how_ for each instance.
18+
19+
DSC can process configuration documents to:
20+
21+
- Retrieve the current state of the defined resource instances with the `dsc config get` command.
22+
- Validate whether the instances are in the desired state with the `dsc config test` command.
23+
- Enforce the desired state for the instances with the `dsc config set` command.
24+
- Export a new configuration document with every instance of a set of resources with the
25+
`dsc config export` command.
26+
27+
Configuration documents are YAML or JSON files that contain a single object. The object's
28+
properties define how DSC processes the document. The top-level properties for a document are:
29+
30+
- `$schema` (required) - Defines the URI for the JSON Schema the document adheres to. DSC
31+
uses this to know how to validate and interpret the document.
32+
- `resources` (required) - Defines the collection of resource instances the document manages.
33+
- `metadata` (optional) - Defines an arbitrary set of annotations for the document. Except for
34+
metadata within the `Microsoft.DSC` property, DSC doesn't validate this data or use it directly.
35+
The annotations can include notes like who authored the document, the last time someone updated
36+
it, or any other information. DSC doesn't use the annotations. The metadata is for documentation
37+
or other tools to use.
38+
39+
DSC applies validation to the `Microsoft.DSC` property. For more information, see the
40+
[DSC Configuration document metadata schema][02] reference.
41+
- `parameters` (optional) - Defines a set of runtime options for the configuration. Parameters can
42+
be referenced by resource instances to reduce duplicate definitions or enable dynamic values.
43+
Parameters can have default values and can be set on any configuration operation.
44+
- `variables` (optional) - Defines a set of reusable values for the configuration. Variables can be
45+
referenced by resource instances to reduce duplicate definitions.
46+
47+
## Defining a configuration document
48+
49+
Minimally, a configuration document defines the `$schema` and `resources` properties. The
50+
`$schema` property must be a valid URI for the DSC configuration document schema. The `resources`
51+
property must define at least one DSC Resource instance.
52+
53+
For example:
54+
55+
```yaml
56+
# example.dsc.config.yaml
57+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
58+
resources:
59+
- name: example key value
60+
type: Microsoft.Windows/Registry
61+
properties:
62+
keyPath: HKCU\example\key
63+
valueName: Example
64+
valueData:
65+
String: This is an example.
66+
```
67+
68+
The example document defines a single resource instance named `example key value`. The instance
69+
uses the `Microsoft.Windows/Registry` resource to declare the following desired state:
70+
71+
- The `example\key` registry key should exist in the system's current user hive.
72+
- The `example\key` registry key should have a value called `Example`.
73+
- The `Example` value should be the string `This is an example`.
74+
75+
The example document is _declarative_. It describes the desired state, not how to put the system
76+
into that state. It relies on the `Microsoft.Windows/Registry` resource to handle getting, testing,
77+
and setting the state of the registry key and value.
78+
79+
For more information about the structure and validation of configuration documents, see
80+
[DSC Configuration document schema reference][03].
81+
82+
### Defining resource instances
83+
84+
As shown in the prior example, configuration documents include a collection of resource instances.
85+
Together, the instances describe the desired state of a system. A configuration document can
86+
include any number of resource instances.
87+
88+
A resource instance declaration always includes:
89+
90+
- `name` - A short, human-readable name for the instance that's unique in the document. This name
91+
is used for logging and it helps describe the purpose of the instance.
92+
- `type` - The [fully qualified type name][04] of the resource that DSC should use to manage the
93+
instance.
94+
- `properties` - The desired state for the instance. DSC validates the values against the
95+
resource's instance schema.
96+
97+
Configuration documents can't include the same instance more than once. Declaring the same instance
98+
with different properties leads to enforcement cycling, where each declaration enforces an
99+
incompatible state for the instance on every run.
100+
101+
## Getting the current state of a configuration
102+
103+
The `dsc config get` command retrieves the current state of the resource instances defined in a
104+
configuration document. DSC also collects any message emitted by the resources during the
105+
operation, indicates whether any of the resources raised an error, and provides metadata about the
106+
operation as a whole and for each resource instance.
107+
108+
```sh
109+
dsc config get --file ./example.config.dsc.yaml
110+
```
111+
112+
```yaml
113+
metadata:
114+
Microsoft.DSC:
115+
version: 3.0.0
116+
operation: get
117+
executionType: actual
118+
startDatetime: 2025-02-24T16:09:40.671454400-06:00
119+
endDatetime: 2025-02-24T16:09:41.850086300-06:00
120+
duration: PT1.1786319S
121+
securityContext: restricted
122+
results:
123+
- metadata:
124+
Microsoft.DSC:
125+
duration: PT0.2751153S
126+
name: example key value
127+
type: Microsoft.Windows/Registry
128+
result:
129+
actualState:
130+
keyPath: HKCU\example\key
131+
_exist: false
132+
messages: []
133+
hadErrors: false
134+
```
135+
136+
## Testing a configuration
137+
138+
The `dsc config test` command compares the current state of the resource instances to their desired
139+
state. The result for each instance includes:
140+
141+
- The desired state for the instance.
142+
- The actual state of the instance.
143+
- Whether the instance is in the desired state.
144+
- The list of properties that are out of the desired state, if any.
145+
146+
DSC also collects any message emitted by the resources during the operation, indicates whether any
147+
of the resources raised an error, and provides metadata about the operation as a whole and for each
148+
resource instance.
149+
150+
```sh
151+
dsc config test --file /example.config.dsc.yaml
152+
```
153+
154+
```yaml
155+
metadata:
156+
Microsoft.DSC:
157+
version: 3.0.0
158+
operation: test
159+
executionType: actual
160+
startDatetime: 2025-02-24T16:11:42.798122500-06:00
161+
endDatetime: 2025-02-24T16:11:43.442216400-06:00
162+
duration: PT0.6440939S
163+
securityContext: restricted
164+
results:
165+
- metadata:
166+
Microsoft.DSC:
167+
duration: PT0.2234078S
168+
name: example key value
169+
type: Microsoft.Windows/Registry
170+
result:
171+
desiredState:
172+
keyPath: HKCU\example\key
173+
valueName: Example
174+
valueData:
175+
String: This is an example.
176+
actualState:
177+
keyPath: HKCU\example\key
178+
_exist: false
179+
inDesiredState: false
180+
differingProperties:
181+
- valueName
182+
- valueData
183+
- _exist
184+
messages: []
185+
hadErrors: false
186+
```
187+
188+
## Enforcing a configuration
189+
190+
The `dsc config set` command enforces the resource instances defined in a configuration document to
191+
their desired state. The result for each instance includes:
192+
193+
- The state of the instance before the operation.
194+
- The state of the instance after the operation.
195+
- Which properties the operation changed, if any.
196+
197+
DSC also collects any message emitted by the resources during the operation, indicates whether any
198+
of the resources raised an error, and provides metadata about the operation as a whole and for each
199+
resource instance.
200+
201+
```sh
202+
dsc config set --file ./example.config.dsc.yaml
203+
```
204+
205+
```yaml
206+
metadata:
207+
Microsoft.DSC:
208+
version: 3.0.0
209+
operation: set
210+
executionType: actual
211+
startDatetime: 2025-02-24T16:13:32.746742600-06:00
212+
endDatetime: 2025-02-24T16:13:33.606785-06:00
213+
duration: PT0.8600424S
214+
securityContext: restricted
215+
results:
216+
- metadata:
217+
Microsoft.DSC:
218+
duration: PT0.4070001S
219+
name: example key value
220+
type: Microsoft.Windows/Registry
221+
result:
222+
beforeState:
223+
keyPath: HKCU\example\key
224+
_exist: false
225+
afterState:
226+
keyPath: HKCU\example\key
227+
valueName: Example
228+
valueData:
229+
String: This is an example.
230+
changedProperties:
231+
- valueName
232+
- valueData
233+
- _exist
234+
messages: []
235+
hadErrors: false
236+
```
237+
238+
## See also
239+
240+
- [DSC Resources][01] to learn about resources.
241+
- [DSC Configuration document schema reference][05]
242+
- [Command line reference for the 'dsc config' command][06]
243+
244+
[01]: ../resources/index.md.md
245+
[02]: ../../reference/schemas/config/metadata.md#microsoftdsc
246+
[03]: ../../reference/schemas/config/document.md
247+
[04]: ../resources/index.md#resource-type-names
248+
[05]: ../../reference/schemas/config/document.md
249+
[06]: ../../reference/cli/config/command.md

0 commit comments

Comments
 (0)