Testing Azure Setup with Pester
  • 20 May 2020
  • 1 Minute to read
  • Contributors
  • Comment
  • Dark
    Light
  • PDF

Testing Azure Setup with Pester

  • Comment
  • Dark
    Light
  • PDF

Article Summary

Ive been wanting to do this for a while and finally got the chance. I needed to check that after a major go live our Azure Estate was in the expected state. I wanted to look to use Powershell and Pester to do this.

With Pester I will be able to create some tests which will check the properties of my Azure Estate to see if they are as I expect. To get started I want to create a simple test which will check all of my resources are in the data centre I expect them to be in. To get started in Powershell I need to import the Pester module which I can do with the command below.

Install-Module Pester -Force -SkipPublisherCheck

To use a Pester test the simplest way to get started is to use the following key words:

Key WordMeaning
DescribeThis is the equivelent of a Test Case
ItThis is the equivelent of a test and is used to express an expectation

Now point to note here that I am fairly new to Pester at this stage so if you want to know more about the details of Pester there are loads of good resources out there.

Next I will access my resources in a resource group and check the they are in the data centre I expect. I can use Get-AzResource to get the resources and then loop over thema and create a test for each resource. The below script shows the full thing in action.

$resourcegroup = 'My-RG'
$resources = Get-AzResource -ResourceGroupName $resourcegroup

Describe 'Azure Resources'{
    foreach ($resource in $resources) {       
        
        It "$($resource.Location) is westus2" {
            $resource.Location | Should Be 'westus2'            
        }               
    }
}

Once I have the basics of Pester going I can start adding other tests as I want to check more advanced scenarios.


Was this article helpful?