Created
August 12, 2024 13:40
-
-
Save mikaelkrief/134d5c328c7dcaba45798d56e134908f to your computer and use it in GitHub Desktop.
Azure Pester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define the resource parameters | |
$resourceGroupName = "YourResourceGroupName" | |
$aksClusterName = "YourAKSClusterName" | |
$expectedLocation = "eastus" # Replace with your expected location | |
$expectedNodeCount = 3 # Replace with your expected node count | |
$expectedKubernetesVersion = "1.25.0" # Replace with your expected Kubernetes version | |
# Import the Az module | |
Import-Module Az | |
# Import Pester for testing | |
Import-Module Pester | |
Describe "Azure AKS Resource Tests" { | |
Context "AKS Cluster Tests" { | |
It "AKS Cluster should exist" { | |
$aksCluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $aksClusterName -ErrorAction SilentlyContinue | |
$aksCluster | Should -Not -BeNullOrEmpty | |
} | |
It "AKS Cluster should be in the correct location" { | |
$aksCluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $aksClusterName | |
$aksCluster.Location | Should -Be $expectedLocation | |
} | |
It "AKS Cluster should have the correct Kubernetes version" { | |
$aksCluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $aksClusterName | |
$aksCluster.KubernetesVersion | Should -Be $expectedKubernetesVersion | |
} | |
It "AKS Cluster should have the expected number of nodes" { | |
$aksCluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $aksClusterName | |
$nodeCount = ($aksCluster.AgentPoolProfiles | Measure-Object -Property Count).Count | |
$nodeCount | Should -Be $expectedNodeCount | |
} | |
} | |
Context "AKS Node Pool Tests" { | |
It "AKS Cluster should have a node pool" { | |
$nodePool = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $aksClusterName -ErrorAction SilentlyContinue | |
$nodePool | Should -Not -BeNullOrEmpty | |
} | |
It "AKS Node Pool should have the correct VM size" { | |
$expectedVmSize = "Standard_DS2_v2" # Replace with your expected VM size | |
$nodePool = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $aksClusterName | |
$nodePool.VmSize | Should -Be $expectedVmSize | |
} | |
It "AKS Node Pool should have autoscaling enabled" { | |
$nodePool = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $aksClusterName | |
$nodePool.EnableAutoScaling | Should -Be $true | |
} | |
} | |
} | |
# Run the Pester tests | |
Invoke-Pester |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment