What are DSC resources?

DSC resources are PowerShell modules that contain both the schema and implementation to determine and set the target node state. The schema is defined in MOF files, and the implementation code is defined in PowerShell script modules. Beginning with PowerShell V5, DSC resources can also be implemented using only PowerShell script files.

This is all well and good for a definition, but we are getting ahead of ourselves. At its simplest definition, a DSC resource is a PowerShell script that can be run against a target node that only changes the system state when it differs from the desired state. Schema MOFs and module folders aside, the core of a DSC resource is the idempotent code that determines the state of the target node and adjusts it until it is in line with what is expected. This code is implemented in PowerShell, so you're already familiar with the language used, which is a huge boost in starting to customize your own DSC resources.

Since DSC resources are authored using PowerShell code, the power is in your hands. It's the same PowerShell code you know and love. This boosts productivity out of the gate, leaving you with the freedom to focus on the actual code that performs the changes, instead of worrying about learning a new way of doing things.

DSC resources are responsible for both testing the current state of a target node and bringing the target node to the expected state. They follow the concepts of idempotency by only changing the system state if it is not in compliance, and they can be run as many times as desired. Even if they are run many times, DSC resources will only change the state if it is not in compliance with the desired state.

DSC resources are the smallest units of change in PowerShell DSC, so, by their very nature, they are much more focused and narrow in the subject matter they address. You will not find a single all-encompassing DSC resource that installs and configures the entirety of a Microsoft SQL Server four-node cluster with alwayson availability, but, instead, you'll find several focused DSC resources that each cover unique and specific task to accomplish. One DSC resource handles installation and basic configuration, while another handles configuration of the cluster and addition of the four nodes, and yet another handles creating or removing databases.

This specification of DSC resources allows you to perform complicated orchestration of multi-node deployments. Rather than a resource that installs a whole SQL cluster across nodes, several individual DSC resources install each component of a SQL cluster, which can be chained across nodes and reboots to accomplish the task. The point is that DSC resources, such as PowerShell Cmdlets, do one thing and in a repeatable, idempotent fashion.

We will delve into more about how DSC resources accomplish this as we progress through this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset