diff --git a/.github/workflows/ms.security.azuresecuritycenter.yml b/.github/workflows/ms.security.azuresecuritycenter.yml index c3e9ee978d..7a931edf5f 100644 --- a/.github/workflows/ms.security.azuresecuritycenter.yml +++ b/.github/workflows/ms.security.azuresecuritycenter.yml @@ -106,8 +106,7 @@ jobs: - name: 'Using test file [${{ matrix.moduleTestFilePaths }}]' uses: ./.github/actions/templates/validateModuleDeployment with: - templateFilePath: '${{ env.modulePath }}/deploy.bicep' - parameterFilePath: '${{ env.modulePath }}/${{ matrix.moduleTestFilePaths }}' + templateFilePath: '${{ env.modulePath }}/${{ matrix.moduleTestFilePaths }}' location: '${{ env.location }}' resourceGroupName: '${{ env.resourceGroupName }}' subscriptionId: '${{ secrets.ARM_SUBSCRIPTION_ID }}' diff --git a/modules/Microsoft.Security/azureSecurityCenter/.test/common/dependencies.bicep b/modules/Microsoft.Security/azureSecurityCenter/.test/common/dependencies.bicep new file mode 100644 index 0000000000..cc24476629 --- /dev/null +++ b/modules/Microsoft.Security/azureSecurityCenter/.test/common/dependencies.bicep @@ -0,0 +1,13 @@ +@description('Optional. The location to deploy to.') +param location string = resourceGroup().location + +@description('Required. The name of the Log Analytics Workspace to create.') +param logAnalyticsWorkspaceName string + +resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2021-06-01' = { + name: logAnalyticsWorkspaceName + location: location +} + +@description('The resource ID of the created Log Analytics Workspace.') +output logAnalyticsWorkspaceResourceId string = logAnalyticsWorkspace.id diff --git a/modules/Microsoft.Security/azureSecurityCenter/.test/common/deploy.test.bicep b/modules/Microsoft.Security/azureSecurityCenter/.test/common/deploy.test.bicep new file mode 100644 index 0000000000..7ae31d9e81 --- /dev/null +++ b/modules/Microsoft.Security/azureSecurityCenter/.test/common/deploy.test.bicep @@ -0,0 +1,51 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes.') +@maxLength(90) +param resourceGroupName string = 'ms.security.azureSecurityCenter-${serviceShort}-rg' + +@description('Optional. The location to deploy resources to.') +param location string = deployment().location + +@description('Optional. A short identifier for the kind of deployment. Should be kept short to not run into resource-name length-constraints.') +param serviceShort string = 'sasccom' + +// =========== // +// Deployments // +// =========== // + +// General resources +// ================= +resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = { + name: resourceGroupName + location: location +} + +module resourceGroupResources 'dependencies.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name, location)}-paramNested' + params: { + logAnalyticsWorkspaceName: 'dep-<>-law-${serviceShort}' + } +} + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + scope: '/subscriptions/${subscription().subscriptionId}' + workspaceId: resourceGroupResources.outputs.logAnalyticsWorkspaceResourceId + securityContactProperties: { + alertNotifications: 'Off' + alertsToAdmins: 'Off' + email: 'foo@contoso.com' + phone: '+12345678' + } + } +} diff --git a/modules/Microsoft.Security/azureSecurityCenter/.test/parameters.json b/modules/Microsoft.Security/azureSecurityCenter/.test/parameters.json deleted file mode 100644 index cfa02a1ddc..0000000000 --- a/modules/Microsoft.Security/azureSecurityCenter/.test/parameters.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "scope": { - "value": "/subscriptions/<>" - }, - "securityContactProperties": { - "value": { - "email": "foo@contoso.com", - "phone": "+12345678", - "alertNotifications": "Off", - "alertsToAdmins": "Off" - } - }, - "workspaceId": { - "value": "/subscriptions/<>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<>-az-law-x-001" - } - } -} diff --git a/modules/Microsoft.Security/azureSecurityCenter/readme.md b/modules/Microsoft.Security/azureSecurityCenter/readme.md index 96c45b4c96..112890b6e5 100644 --- a/modules/Microsoft.Security/azureSecurityCenter/readme.md +++ b/modules/Microsoft.Security/azureSecurityCenter/readme.md @@ -108,7 +108,7 @@ The following module usage examples are retrieved from the content of the files >**Note**: Each example lists all the required parameters first, followed by the rest - each in alphabetical order. -

Example 1: Parameters

+

Example 1: Common

@@ -116,12 +116,10 @@ The following module usage examples are retrieved from the content of the files ```bicep module azureSecurityCenter './Microsoft.Security/azureSecurityCenter/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-AzureSecurityCenter' + name: '${uniqueString(deployment().name)}-test-sasccom' params: { // Required parameters - scope: '/subscriptions/<>' - workspaceId: '/subscriptions/<>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<>-az-law-x-001' - // Non-required parameters + workspaceId: '' securityContactProperties: { alertNotifications: 'Off' alertsToAdmins: 'Off' @@ -145,13 +143,9 @@ module azureSecurityCenter './Microsoft.Security/azureSecurityCenter/deploy.bice "contentVersion": "1.0.0.0", "parameters": { // Required parameters - "scope": { - "value": "/subscriptions/<>" - }, "workspaceId": { - "value": "/subscriptions/<>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<>-az-law-x-001" + "value": "" }, - // Non-required parameters "securityContactProperties": { "value": { "alertNotifications": "Off",