-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added post-deployment test support (#1036)
## Description > **Note:** Test file changes for key vault are just for illustration purposes - Introduced 2 additional steps to deploy action that will look for Pester test files anywhere in a e2e test's folder (or nested folder, if desired), run the contained tests and publish the results - If no test was found, the publish results step will be skipped - By default, the action will pass in one parameter to the test files that MUST be implemented: `[hashtable] $TestInputData`. This parameter will automatically contain the test file outputs + the path to the test file. For example ```json { "TestInputData": { "ModuleTestFolderPath": "/home/runner/work/bicep-registry-modules/bicep-registry-modules/avm/res/key-vault/vault/tests/e2e/private-endpoint", "DeploymentOutputs": { "resourceId": { "type": "string", "value": "/subscriptions/1111111/resourcegroups/(...)" } } } } ``` - Example [run](https://github.com/AlexanderSehr/bicep-registry-modules/actions/runs/7944560531/job/21690223560) | Pipeline | | - | | [![avm.res.key-vault.vault](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml/badge.svg?branch=users%2Falsehr%2FpostDeploymentTest&event=workflow_dispatch)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml) | --------- Co-authored-by: Erika Gressi <[email protected]> Co-authored-by: ChrisSidebotham-MSFT <[email protected]>
- Loading branch information
1 parent
14ed0f1
commit 5b2380a
Showing
5 changed files
with
164 additions
and
10 deletions.
There are no files selected for viewing
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
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
39 changes: 39 additions & 0 deletions
39
avm/res/key-vault/vault/tests/e2e/private-endpoint/tests/connectivity.tests.ps1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
###################################### | ||
## Additional post-deployment tests ## | ||
###################################### | ||
## | ||
## You can add any custom post-deployment validation tests you want here, or add them spread accross multiple test files in the test case folder. | ||
## | ||
########################### | ||
|
||
param ( | ||
[Parameter(Mandatory = $false)] | ||
[hashtable] $TestInputData = @{} | ||
) | ||
|
||
Describe 'Validate private endpoint deployment' { | ||
|
||
Context 'Validate sucessful deployment' { | ||
|
||
It "Private endpoints should be deployed in resource group" { | ||
|
||
$keyVaultResourceId = $TestInputData.DeploymentOutputs.resourceId.Value | ||
$testResourceGroup = ($keyVaultResourceId -split '\/')[4] | ||
$deployedPrivateEndpoints = Get-AzPrivateEndpoint -ResourceGroupName $testResourceGroup | ||
$deployedPrivateEndpoints.Count | Should -BeGreaterThan 0 | ||
} | ||
|
||
It 'Private endpoint should have role assignment' { | ||
|
||
$keyVaultResourceId = $TestInputData.DeploymentOutputs.resourceId.Value | ||
$testResourceGroup = ($keyVaultResourceId -split '\/')[4] | ||
$deployedPrivateEndpoints = Get-AzPrivateEndpoint -ResourceGroupName $testResourceGroup | ||
|
||
$firstPrivateEndpointResourceId = $deployedPrivateEndpoints[0].Id | ||
$firstPrivateEndpointName = ($firstPrivateEndpointResourceId -split '\/')[-1] | ||
|
||
$roleAssignments = Get-AzRoleAssignment -ResourceName $firstPrivateEndpointName -ResourceType 'Microsoft.Network/privateEndpoints' -ResourceGroupName $testResourceGroup | ||
$roleAssignments.Count | Should -BeGreaterThan 0 | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
avm/res/key-vault/vault/tests/e2e/private-endpoint/tests/resource.tests.ps1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
###################################### | ||
## Additional post-deployment tests ## | ||
###################################### | ||
## | ||
## You can add any custom post-deployment validation tests you want here, or add them spread accross multiple test files in the test case folder. | ||
## | ||
########################### | ||
|
||
param ( | ||
[Parameter(Mandatory = $false)] | ||
[hashtable] $TestInputData = @{} | ||
) | ||
|
||
Describe 'Validate Key Vault' { | ||
|
||
It 'Public endpoint should be disabled' { | ||
|
||
$keyVaultResourceId = $TestInputData.DeploymentOutputs.resourceId.Value | ||
|
||
$deployedResource = Get-AzResource -ResourceId $keyVaultResourceId | ||
|
||
$deployedResource.Properties.publicNetworkAccess | Should -Be 'Disabled' | ||
} | ||
} |
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