diff --git a/.github/workflows/ms.consumption.budgets.yml b/.github/workflows/ms.consumption.budgets.yml index c892c5b374..046afb8bce 100644 --- a/.github/workflows/ms.consumption.budgets.yml +++ b/.github/workflows/ms.consumption.budgets.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.Consumption/budgets/.test/common/deploy.test.bicep b/modules/Microsoft.Consumption/budgets/.test/common/deploy.test.bicep new file mode 100644 index 0000000000..55e568ee90 --- /dev/null +++ b/modules/Microsoft.Consumption/budgets/.test/common/deploy.test.bicep @@ -0,0 +1,29 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@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 = 'cbcom' + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + amount: 500 + contactEmails: [ + 'dummy@contoso.com' + ] + thresholds: [ + 50 + 75 + 90 + 100 + 110 + ] + } +} diff --git a/modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep b/modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep new file mode 100644 index 0000000000..2941cb87a1 --- /dev/null +++ b/modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep @@ -0,0 +1,22 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@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 = 'cbmin' + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + amount: 500 + contactEmails: [ + 'dummy@contoso.com' + ] + } +} diff --git a/modules/Microsoft.Consumption/budgets/.test/parameters.json b/modules/Microsoft.Consumption/budgets/.test/parameters.json deleted file mode 100644 index 0534e322a0..0000000000 --- a/modules/Microsoft.Consumption/budgets/.test/parameters.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "Monthly-Cost-Budget" - }, - "amount": { - "value": 500 - }, - "thresholds": { - "value": [ - 50, - 75, - 90, - 100, - 110 - ] - }, - "contactEmails": { - "value": [ - "dummy@contoso.com" - ] - } - } -} diff --git a/modules/Microsoft.Consumption/budgets/deploy.bicep b/modules/Microsoft.Consumption/budgets/deploy.bicep index 439d6e4808..f1c93babd9 100644 --- a/modules/Microsoft.Consumption/budgets/deploy.bicep +++ b/modules/Microsoft.Consumption/budgets/deploy.bicep @@ -40,13 +40,13 @@ param thresholds array = [ 110 ] -@description('Optional. The list of email addresses to send the budget notification to when the thresholds are exceeded.') +@description('Conditional. The list of email addresses to send the budget notification to when the thresholds are exceeded. Required if neither `contactRoles` nor `actionGroups` was provided.') param contactEmails array = [] -@description('Optional. The list of contact roles to send the budget notification to when the thresholds are exceeded.') +@description('Conditional. The list of contact roles to send the budget notification to when the thresholds are exceeded. Required if neither `contactEmails` nor `actionGroups` was provided.') param contactRoles array = [] -@description('Optional. List of action group resource IDs that will receive the alert.') +@description('Conditional. List of action group resource IDs that will receive the alert. Required if neither `contactEmails` nor `contactEmails` was provided.') param actionGroups array = [] @description('Optional. Enable telemetry via the Customer Usage Attribution ID (GUID).') diff --git a/modules/Microsoft.Consumption/budgets/readme.md b/modules/Microsoft.Consumption/budgets/readme.md index 0ca622a464..b6c07b6f88 100644 --- a/modules/Microsoft.Consumption/budgets/readme.md +++ b/modules/Microsoft.Consumption/budgets/readme.md @@ -24,13 +24,17 @@ This module deploys budgets for subscriptions. | `amount` | int | The total amount of cost or usage to track with the budget. | | `name` | string | The name of the budget. | +**Conditional parameters** +| Parameter Name | Type | Description | +| :-- | :-- | :-- | +| `actionGroups` | array | List of action group resource IDs that will receive the alert. Required if neither `contactEmails` nor `contactEmails` was provided. | +| `contactEmails` | array | The list of email addresses to send the budget notification to when the thresholds are exceeded. Required if neither `contactRoles` nor `actionGroups` was provided. | +| `contactRoles` | array | The list of contact roles to send the budget notification to when the thresholds are exceeded. Required if neither `contactEmails` nor `actionGroups` was provided. | + **Optional parameters** | Parameter Name | Type | Default Value | Allowed Values | Description | | :-- | :-- | :-- | :-- | :-- | -| `actionGroups` | array | `[]` | | List of action group resource IDs that will receive the alert. | | `category` | string | `'Cost'` | `[Cost, Usage]` | The category of the budget, whether the budget tracks cost or usage. | -| `contactEmails` | array | `[]` | | The list of email addresses to send the budget notification to when the thresholds are exceeded. | -| `contactRoles` | array | `[]` | | The list of contact roles to send the budget notification to when the thresholds are exceeded. | | `enableDefaultTelemetry` | bool | `True` | | Enable telemetry via the Customer Usage Attribution ID (GUID). | | `endDate` | string | `''` | | The end date for the budget. If not provided, it will default to 10 years from the start date. | | `location` | string | `[deployment().location]` | | Location deployment metadata. | @@ -57,7 +61,7 @@ The following module usage examples are retrieved from the content of the files >**Note**: The name of each example is based on the name of the file from which it is taken. >**Note**: Each example lists all the required parameters first, followed by the rest - each in alphabetical order. -

Example 1: Parameters

+

Example 1: Common

@@ -65,11 +69,11 @@ The following module usage examples are retrieved from the content of the files ```bicep module budgets './Microsoft.Consumption/budgets/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-Budgets' + name: '${uniqueString(deployment().name)}-test-cbcom' params: { // Required parameters amount: 500 - name: 'Monthly-Cost-Budget' + name: '<>cbcom001' // Non-required parameters contactEmails: [ 'dummy@contoso.com' @@ -102,7 +106,7 @@ module budgets './Microsoft.Consumption/budgets/deploy.bicep' = { "value": 500 }, "name": { - "value": "Monthly-Cost-Budget" + "value": "<>cbcom001" }, // Non-required parameters "contactEmails": { @@ -125,3 +129,56 @@ module budgets './Microsoft.Consumption/budgets/deploy.bicep' = {

+ +

Example 2: Min

+ +
+ +via Bicep module + +```bicep +module budgets './Microsoft.Consumption/budgets/deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-cbmin' + params: { + // Required parameters + amount: 500 + name: '<>cbmin001' + // Non-required parameters + contactEmails: [ + 'dummy@contoso.com' + ] + } +} +``` + +
+

+ +

+ +via JSON Parameter file + +```json +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + // Required parameters + "amount": { + "value": 500 + }, + "name": { + "value": "<>cbmin001" + }, + // Non-required parameters + "contactEmails": { + "value": [ + "dummy@contoso.com" + ] + } + } +} +``` + +
+