Build your Azure lab with DSC and validate it using Pester – 1/3

 

Here is another post about DSC & Pester.. Yes, because they are truly the perfect combo to work with. Just do you script and Pester will test everything you need for you 🙂 (I know i’m repeating myself…)

So let’s go build our lab. What is neeeded in order to build my lab:

  • A domain controller
  • A filer
  • A Pull Server
  • 2-3 clients in order to test our Pull server is doding good

So let’s start by the main part that is building the VM infrastructure. Microsoft released while ago a DSC Resource for Azure, which is called xAzure. This module needs the Azure SDK available on your server installed before using it. You can follow the full process to install it here !

Now, installing the xAzure resource.

Nothing really difficult here 😉

So, let’s check what we can do with this resource !

xAzures ResourcesWe have everything needed to build the lab.

Authentication

In order to build our VMs, we need of course to be connected to our account, so the first thing to do is to get the .publishedsetting file. To find it, you just have to run a little cmdlet

Once you are logged with your Azure account, register the published file.

Now let’s have a look about how use the xAzureSubscription resource. As always, Get-DSCResource is your friend !

So we have to find the Azure Subscription Name, it’s the only thing we don’t have a clue what it is… In order to do this, we need to authenticated ourself to the portal using powershell  cmdlets and list all our subscriptions.

Now we have the name of our subscriptions

Ok so let’s build our dsc block for authentication.

Configure your subscription

In order to get our VMs working together we need to get them on the same network with static ip addresses. But right now this is not the question. We’ll configure affinity group and create the associated service.

Once again, let’s use our good old friend Get-DscResource to check the correct syntax !

So in order to create an affinity group, we’ll need at least the location and the name of the affinity group !

The affinity location can be one of these values:

So let’s build the resource block…

Once the affinity group is created, in order to build our VMs we need to create a service to attach it on the affinity group. Note that we use DependsOn to guarantee the orchestration of resources execution.

 

Create Virtual Machines

Now it’s time to create our virtual machines. Ok, let’s go to see what we need to build our stuff.

So, we need the vhd image, the service name and the affinity group name. But in order to get our Windows customized, let’s specify too the credential, and force it to Windows OS.

Let’s first focus about how get the images available for the affinity group location.

Ok, now we have our vhd list, now time to add the last blocks to our configuration

 Validate your created infrastructure with Pester

Once your configuration is applied, this Pester script will help you validate your infra. In order to do this, just create a script named Azure_Lab.tests.ps1, and copy/past this in the script

Now, navigate to the script folder, and do:

And Tadaaaaaaa !

Pester execution

Well, that’s all for now, in the next part we’ll see all methods available to upload and execute script (DSC configuration) on target VMs.

Wish for you, your family and friends, all the best for next year!