From 189f756270b0d26a9968641b83c921dd0b302b62 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Mon, 5 Sep 2022 20:21:17 +0200 Subject: [PATCH 1/7] Updated Consumption budgets to new dependencies approach --- .github/workflows/ms.consumption.budgets.yml | 3 +- .../budgets/.test/default/deploy.test.bicep | 29 +++++++++++ .../budgets/.test/min/deploy.test.bicep | 19 +++++++ .../budgets/.test/parameters.json | 26 ---------- .../Microsoft.Consumption/budgets/readme.md | 51 +++++++++++++++++-- 5 files changed, 96 insertions(+), 32 deletions(-) create mode 100644 modules/Microsoft.Consumption/budgets/.test/default/deploy.test.bicep create mode 100644 modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep delete mode 100644 modules/Microsoft.Consumption/budgets/.test/parameters.json 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/default/deploy.test.bicep b/modules/Microsoft.Consumption/budgets/.test/default/deploy.test.bicep new file mode 100644 index 0000000000..cef7239757 --- /dev/null +++ b/modules/Microsoft.Consumption/budgets/.test/default/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 = 'cbdef' + +// ============== // +// 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..0660e02484 --- /dev/null +++ b/modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep @@ -0,0 +1,19 @@ +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 + } +} 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/readme.md b/modules/Microsoft.Consumption/budgets/readme.md index 0ca622a464..ffe71f6c0a 100644 --- a/modules/Microsoft.Consumption/budgets/readme.md +++ b/modules/Microsoft.Consumption/budgets/readme.md @@ -57,7 +57,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: Default

@@ -65,11 +65,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-cbdef' params: { // Required parameters amount: 500 - name: 'Monthly-Cost-Budget' + name: '<>cbdef001' // Non-required parameters contactEmails: [ 'dummy@contoso.com' @@ -102,7 +102,7 @@ module budgets './Microsoft.Consumption/budgets/deploy.bicep' = { "value": 500 }, "name": { - "value": "Monthly-Cost-Budget" + "value": "<>cbdef001" }, // Non-required parameters "contactEmails": { @@ -125,3 +125,46 @@ 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' + } +} +``` + +
+

+ +

+ +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" + } + } +} +``` + +
+

From 8981d82cc5a1ac35658340ee3f8f1ea00df615b6 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Mon, 5 Sep 2022 20:47:17 +0200 Subject: [PATCH 2/7] Updated parameters --- .../budgets/.test/min/deploy.test.bicep | 3 +++ .../budgets/deploy.bicep | 6 +++--- .../Microsoft.Consumption/budgets/readme.md | 20 ++++++++++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep b/modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep index 0660e02484..ecbfe43f35 100644 --- a/modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep +++ b/modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep @@ -15,5 +15,8 @@ module testDeployment '../../deploy.bicep' = { params: { name: '<>${serviceShort}001' amount: 500 + contactEmails: [ + 'dummy@contoso.com' + ] } } diff --git a/modules/Microsoft.Consumption/budgets/deploy.bicep b/modules/Microsoft.Consumption/budgets/deploy.bicep index 439d6e4808..82271975d3 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` or `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` or `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` or `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 ffe71f6c0a..efa25770dc 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` or `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` or `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` or `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. | @@ -139,6 +143,10 @@ module budgets './Microsoft.Consumption/budgets/deploy.bicep' = { // Required parameters amount: 500 name: '<>cbmin001' + // Non-required parameters + contactEmails: [ + 'dummy@contoso.com' + ] } } ``` @@ -161,6 +169,12 @@ module budgets './Microsoft.Consumption/budgets/deploy.bicep' = { }, "name": { "value": "<>cbmin001" + }, + // Non-required parameters + "contactEmails": { + "value": [ + "dummy@contoso.com" + ] } } } From bdd1dca3dca156ff8a1ef64931b885846178a597 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Fri, 9 Sep 2022 12:13:41 +0200 Subject: [PATCH 3/7] Update modules/Microsoft.Consumption/budgets/readme.md Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com> --- modules/Microsoft.Consumption/budgets/readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/Microsoft.Consumption/budgets/readme.md b/modules/Microsoft.Consumption/budgets/readme.md index efa25770dc..a2b9716b72 100644 --- a/modules/Microsoft.Consumption/budgets/readme.md +++ b/modules/Microsoft.Consumption/budgets/readme.md @@ -27,9 +27,9 @@ This module deploys budgets for subscriptions. **Conditional parameters** | Parameter Name | Type | Description | | :-- | :-- | :-- | -| `actionGroups` | array | List of action group resource IDs that will receive the alert. Required if neither `contactEmails` or `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` or `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` or `actionGroups` was provided. | +| `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 | From 95481677925f7f4246688477cc02a77ffb3ca33c Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Fri, 9 Sep 2022 12:13:46 +0200 Subject: [PATCH 4/7] Update modules/Microsoft.Consumption/budgets/deploy.bicep Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com> --- modules/Microsoft.Consumption/budgets/deploy.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Consumption/budgets/deploy.bicep b/modules/Microsoft.Consumption/budgets/deploy.bicep index 82271975d3..160e853115 100644 --- a/modules/Microsoft.Consumption/budgets/deploy.bicep +++ b/modules/Microsoft.Consumption/budgets/deploy.bicep @@ -46,7 +46,7 @@ param contactEmails array = [] @description('Conditional. The list of contact roles to send the budget notification to when the thresholds are exceeded. Required if neither `contactEmails` or `actionGroups` was provided.') param contactRoles array = [] -@description('Conditional. List of action group resource IDs that will receive the alert. Required if neither `contactEmails` or `contactEmails` was provided.') +@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).') From ce319df8a969935f2771532c76687cdbd6e788c3 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Fri, 9 Sep 2022 12:13:53 +0200 Subject: [PATCH 5/7] Update modules/Microsoft.Consumption/budgets/deploy.bicep Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com> --- modules/Microsoft.Consumption/budgets/deploy.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Consumption/budgets/deploy.bicep b/modules/Microsoft.Consumption/budgets/deploy.bicep index 160e853115..0abf4c0cc9 100644 --- a/modules/Microsoft.Consumption/budgets/deploy.bicep +++ b/modules/Microsoft.Consumption/budgets/deploy.bicep @@ -43,7 +43,7 @@ param thresholds array = [ @description('Conditional. The list of email addresses to send the budget notification to when the thresholds are exceeded. Required if neither `contactRoles` or `actionGroups` was provided.') param contactEmails array = [] -@description('Conditional. The list of contact roles to send the budget notification to when the thresholds are exceeded. Required if neither `contactEmails` or `actionGroups` was provided.') +@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('Conditional. List of action group resource IDs that will receive the alert. Required if neither `contactEmails` nor `contactEmails` was provided.') From 977657428e8284f7755a411a896e38ea6a71b12e Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Fri, 9 Sep 2022 12:14:03 +0200 Subject: [PATCH 6/7] Update modules/Microsoft.Consumption/budgets/deploy.bicep Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com> --- modules/Microsoft.Consumption/budgets/deploy.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Consumption/budgets/deploy.bicep b/modules/Microsoft.Consumption/budgets/deploy.bicep index 0abf4c0cc9..f1c93babd9 100644 --- a/modules/Microsoft.Consumption/budgets/deploy.bicep +++ b/modules/Microsoft.Consumption/budgets/deploy.bicep @@ -40,7 +40,7 @@ param thresholds array = [ 110 ] -@description('Conditional. The list of email addresses to send the budget notification to when the thresholds are exceeded. Required if neither `contactRoles` or `actionGroups` was provided.') +@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('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.') From 3bb5f2e6d7605996a1b5f648ceab8635de666648 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Fri, 9 Sep 2022 13:13:31 +0200 Subject: [PATCH 7/7] Updated comments --- .../budgets/.test/{default => common}/deploy.test.bicep | 4 ++-- .../budgets/.test/min/deploy.test.bicep | 2 +- modules/Microsoft.Consumption/budgets/readme.md | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) rename modules/Microsoft.Consumption/budgets/.test/{default => common}/deploy.test.bicep (81%) diff --git a/modules/Microsoft.Consumption/budgets/.test/default/deploy.test.bicep b/modules/Microsoft.Consumption/budgets/.test/common/deploy.test.bicep similarity index 81% rename from modules/Microsoft.Consumption/budgets/.test/default/deploy.test.bicep rename to modules/Microsoft.Consumption/budgets/.test/common/deploy.test.bicep index cef7239757..55e568ee90 100644 --- a/modules/Microsoft.Consumption/budgets/.test/default/deploy.test.bicep +++ b/modules/Microsoft.Consumption/budgets/.test/common/deploy.test.bicep @@ -3,8 +3,8 @@ 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 = 'cbdef' +@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 // diff --git a/modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep b/modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep index ecbfe43f35..2941cb87a1 100644 --- a/modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep +++ b/modules/Microsoft.Consumption/budgets/.test/min/deploy.test.bicep @@ -3,7 +3,7 @@ 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') +@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' // ============== // diff --git a/modules/Microsoft.Consumption/budgets/readme.md b/modules/Microsoft.Consumption/budgets/readme.md index a2b9716b72..b6c07b6f88 100644 --- a/modules/Microsoft.Consumption/budgets/readme.md +++ b/modules/Microsoft.Consumption/budgets/readme.md @@ -61,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: Default

+

Example 1: Common

@@ -69,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)}-test-cbdef' + name: '${uniqueString(deployment().name)}-test-cbcom' params: { // Required parameters amount: 500 - name: '<>cbdef001' + name: '<>cbcom001' // Non-required parameters contactEmails: [ 'dummy@contoso.com' @@ -106,7 +106,7 @@ module budgets './Microsoft.Consumption/budgets/deploy.bicep' = { "value": 500 }, "name": { - "value": "<>cbdef001" + "value": "<>cbcom001" }, // Non-required parameters "contactEmails": {