How to pass in values from file and test if deployed

Hi.

I’m trying to validate the infrastructure being deployed into Azure. What i am looking to do is populate a JSON file with values and then pull the values in, and then check that what is listed in the JSON has been deployed.

So i am getting all resourcesGroups that have been deployed and then trying to check that against whats in my JSON file.

Describe 'Resource Groups' {
    BeforeDiscovery {
        $r = Get-Content .\DevTest.Parameters.json | ConvertFrom-Json -AsHashtable
        $resourceGroup = $R.resourceGroups.Values
    }
    Context 'Checking Resource Group <item>' -Foreach $resourceGroup  {
        BeforeAll {
           $deployResourceGroups =  (Get-AzResourceGroup).ResourceGroupName
                #Not sure what i shuould put here?
        }
        It "Checking resourceGroup exists" {
            $resourceGroup | Should -Be $expectedResultName
        }
        
    }   
}

But i can’t get this to work, so hoping someone can point be in the right direction?

Thanks

you are using -Foreach so you should be accessing the $_ inside the context block than the whole $resourceGroup collection.

and the assertion will be with contain than should be as $deployResourceGroups is a collection of existing ResourceGroup names.

$expectedResultName | Should -Contain $_

Should -Contain | Pester

Thanks kvprasoon, that makes sense. It’s working now and i have more the -foreach into the IT block which makes it a bit cleaner, but now I can’t pass in the name of the resourceGroup into the it block statement.
I would like it to write out [+] Checking resourceGroup resourceGroupName exists 2ms (1ms|1ms
but instead, i get
[+] Checking resourceGroup exists 2ms (1ms|1ms.

Because i have moved the -foreach into the IT block i can’t user $_ in the IT block?

Any ideas?

Thanks

Make sure you have used it right, please check the example in below doc.

It | Pester