diff --git a/.github/workflows/ms.resources.deploymentscripts.yml b/.github/workflows/ms.resources.deploymentscripts.yml index c317b860ef..815ed47236 100644 --- a/.github/workflows/ms.resources.deploymentscripts.yml +++ b/.github/workflows/ms.resources.deploymentscripts.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.Resources/deploymentScripts/.test/cli.parameters.json b/modules/Microsoft.Resources/deploymentScripts/.test/cli.parameters.json deleted file mode 100644 index e3e775a93d..0000000000 --- a/modules/Microsoft.Resources/deploymentScripts/.test/cli.parameters.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "<>-az-ds-cli-001" - }, - "userAssignedIdentities": { - "value": { - "/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001": {} - } - }, - "kind": { - "value": "AzureCLI" - }, - "azCliVersion": { - "value": "2.15.0" - }, - "scriptContent": { - "value": "echo \"Hello from inside the script\"" - }, - "retentionInterval": { - "value": "P1D" - }, - "runOnce": { - "value": false - }, - "cleanupPreference": { - "value": "Always" - }, - "timeout": { - "value": "PT30M" - } - } -} diff --git a/modules/Microsoft.Resources/deploymentScripts/.test/cli/dependencies.bicep b/modules/Microsoft.Resources/deploymentScripts/.test/cli/dependencies.bicep new file mode 100644 index 0000000000..eb82ada472 --- /dev/null +++ b/modules/Microsoft.Resources/deploymentScripts/.test/cli/dependencies.bicep @@ -0,0 +1,13 @@ +@description('Optional. The location to deploy resources to.') +param location string = resourceGroup().location + +@description('Required. The name of the managed identity to create.') +param managedIdentityName string + +resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = { + name: managedIdentityName + location: location +} + +@description('The resource ID of the created managed identity.') +output managedIdentityResourceId string = managedIdentity.id diff --git a/modules/Microsoft.Resources/deploymentScripts/.test/cli/deploy.test.bicep b/modules/Microsoft.Resources/deploymentScripts/.test/cli/deploy.test.bicep new file mode 100644 index 0000000000..5472d7d541 --- /dev/null +++ b/modules/Microsoft.Resources/deploymentScripts/.test/cli/deploy.test.bicep @@ -0,0 +1,55 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes.') +@maxLength(90) +param resourceGroupName string = 'ms.resources.deploymentscripts-${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 = 'rdscli' + +// =========== // +// 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: { + managedIdentityName: 'dep-<>-msi-${serviceShort}' + } +} + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + azCliVersion: '2.41.0' + cleanupPreference: 'Always' + kind: 'AzureCLI' + retentionInterval: 'P1D' + runOnce: false + scriptContent: 'echo \'echo echo echo\'' + timeout: 'PT30M' + userAssignedIdentities: { + '${resourceGroupResources.outputs.managedIdentityResourceId}': {} + } + } +} diff --git a/modules/Microsoft.Resources/deploymentScripts/.test/ps.parameters.json b/modules/Microsoft.Resources/deploymentScripts/.test/ps.parameters.json deleted file mode 100644 index accc14b0b0..0000000000 --- a/modules/Microsoft.Resources/deploymentScripts/.test/ps.parameters.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "<>-az-ds-ps-001" - }, - "lock": { - "value": "CanNotDelete" - }, - "userAssignedIdentities": { - "value": { - "/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001": {} - } - }, - "kind": { - "value": "AzurePowerShell" - }, - "azPowerShellVersion": { - "value": "3.0" - }, - "scriptContent": { - "value": "Write-Host 'Running PowerShell from template'" - }, - "retentionInterval": { - "value": "P1D" - }, - "runOnce": { - "value": false - }, - "cleanupPreference": { - "value": "Always" - }, - "timeout": { - "value": "PT30M" - } - } -} diff --git a/modules/Microsoft.Resources/deploymentScripts/.test/ps/dependencies.bicep b/modules/Microsoft.Resources/deploymentScripts/.test/ps/dependencies.bicep new file mode 100644 index 0000000000..eb82ada472 --- /dev/null +++ b/modules/Microsoft.Resources/deploymentScripts/.test/ps/dependencies.bicep @@ -0,0 +1,13 @@ +@description('Optional. The location to deploy resources to.') +param location string = resourceGroup().location + +@description('Required. The name of the managed identity to create.') +param managedIdentityName string + +resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = { + name: managedIdentityName + location: location +} + +@description('The resource ID of the created managed identity.') +output managedIdentityResourceId string = managedIdentity.id diff --git a/modules/Microsoft.Resources/deploymentScripts/.test/ps/deploy.test.bicep b/modules/Microsoft.Resources/deploymentScripts/.test/ps/deploy.test.bicep new file mode 100644 index 0000000000..96e4d6bb5a --- /dev/null +++ b/modules/Microsoft.Resources/deploymentScripts/.test/ps/deploy.test.bicep @@ -0,0 +1,56 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes.') +@maxLength(90) +param resourceGroupName string = 'ms.resources.deploymentscripts-${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 = 'rdsps' + +// =========== // +// 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: { + managedIdentityName: 'dep-<>-msi-${serviceShort}' + } +} + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + azPowerShellVersion: '8.0' + cleanupPreference: 'Always' + kind: 'AzurePowerShell' + lock: 'CanNotDelete' + retentionInterval: 'P1D' + runOnce: false + scriptContent: 'Write-Host \'The cake is a lie!\'' + timeout: 'PT30M' + userAssignedIdentities: { + '${resourceGroupResources.outputs.managedIdentityResourceId}': {} + } + } +} diff --git a/modules/Microsoft.Resources/deploymentScripts/readme.md b/modules/Microsoft.Resources/deploymentScripts/readme.md index 9d856ecb6a..44d9d1aeb4 100644 --- a/modules/Microsoft.Resources/deploymentScripts/readme.md +++ b/modules/Microsoft.Resources/deploymentScripts/readme.md @@ -162,20 +162,20 @@ The following module usage examples are retrieved from the content of the files ```bicep module deploymentScripts './Microsoft.Resources/deploymentScripts/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-DeploymentScripts' + name: '${uniqueString(deployment().name)}-test-rdscli' params: { // Required parameters - name: '<>-az-ds-cli-001' + name: '<>rdscli001' // Non-required parameters - azCliVersion: '2.15.0' + azCliVersion: '2.41.0' cleanupPreference: 'Always' kind: 'AzureCLI' retentionInterval: 'P1D' runOnce: false - scriptContent: 'echo \'Hello from inside the script\'' + scriptContent: 'echo \'echo echo echo\'' timeout: 'PT30M' userAssignedIdentities: { - '/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001': {} + '': {} } } } @@ -195,11 +195,11 @@ module deploymentScripts './Microsoft.Resources/deploymentScripts/deploy.bicep' "parameters": { // Required parameters "name": { - "value": "<>-az-ds-cli-001" + "value": "<>rdscli001" }, // Non-required parameters "azCliVersion": { - "value": "2.15.0" + "value": "2.41.0" }, "cleanupPreference": { "value": "Always" @@ -214,14 +214,14 @@ module deploymentScripts './Microsoft.Resources/deploymentScripts/deploy.bicep' "value": false }, "scriptContent": { - "value": "echo \"Hello from inside the script\"" + "value": "echo \"echo echo echo\"" }, "timeout": { "value": "PT30M" }, "userAssignedIdentities": { "value": { - "/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001": {} + "": {} } } } @@ -239,21 +239,21 @@ module deploymentScripts './Microsoft.Resources/deploymentScripts/deploy.bicep' ```bicep module deploymentScripts './Microsoft.Resources/deploymentScripts/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-DeploymentScripts' + name: '${uniqueString(deployment().name)}-test-rdsps' params: { // Required parameters - name: '<>-az-ds-ps-001' + name: '<>rdsps001' // Non-required parameters - azPowerShellVersion: '3.0' + azPowerShellVersion: '8.0' cleanupPreference: 'Always' kind: 'AzurePowerShell' lock: 'CanNotDelete' retentionInterval: 'P1D' runOnce: false - scriptContent: 'Write-Host 'Running PowerShell from template'' + scriptContent: 'Write-Host \'The cake is a lie!\'' timeout: 'PT30M' userAssignedIdentities: { - '/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001': {} + '': {} } } } @@ -273,11 +273,11 @@ module deploymentScripts './Microsoft.Resources/deploymentScripts/deploy.bicep' "parameters": { // Required parameters "name": { - "value": "<>-az-ds-ps-001" + "value": "<>rdsps001" }, // Non-required parameters "azPowerShellVersion": { - "value": "3.0" + "value": "8.0" }, "cleanupPreference": { "value": "Always" @@ -295,14 +295,14 @@ module deploymentScripts './Microsoft.Resources/deploymentScripts/deploy.bicep' "value": false }, "scriptContent": { - "value": "Write-Host 'Running PowerShell from template'" + "value": "Write-Host \"The cake is a lie!\"" }, "timeout": { "value": "PT30M" }, "userAssignedIdentities": { "value": { - "/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001": {} + "": {} } } }