From d0ef787650abfab4f135e61ba507ab37a8e93b44 Mon Sep 17 00:00:00 2001 From: Seif Bassem <38246040+sebassem@users.noreply.github.com> Date: Wed, 6 Dec 2023 18:44:51 +0200 Subject: [PATCH] Add Storage Account Management Policy module --- .../management-policy/README.md | 71 +++++++++++++++ .../management-policy/main.bicep | 49 +++++++++++ .../management-policy/main.json | 86 +++++++++++++++++++ .../management-policy/version.json | 7 ++ 4 files changed, 213 insertions(+) create mode 100644 src/carml/v0.6.0/Storage/storage-account/management-policy/README.md create mode 100644 src/carml/v0.6.0/Storage/storage-account/management-policy/main.bicep create mode 100644 src/carml/v0.6.0/Storage/storage-account/management-policy/main.json create mode 100644 src/carml/v0.6.0/Storage/storage-account/management-policy/version.json diff --git a/src/carml/v0.6.0/Storage/storage-account/management-policy/README.md b/src/carml/v0.6.0/Storage/storage-account/management-policy/README.md new file mode 100644 index 00000000..e5ea4753 --- /dev/null +++ b/src/carml/v0.6.0/Storage/storage-account/management-policy/README.md @@ -0,0 +1,71 @@ +# Storage Account Management Policies `[Microsoft.Storage/storageAccounts/managementPolicies]` + +This module deploys a Storage Account Management Policy. + +## Navigation + +- [Resource Types](#resource-types) +- [Parameters](#parameters) +- [Outputs](#outputs) +- [Cross-referenced modules](#cross-referenced-modules) + +## Resource Types + +| Resource Type | API Version | +| :-- | :-- | +| `Microsoft.Storage/storageAccounts/managementPolicies` | [2023-01-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Storage/storageAccounts/managementPolicies) | + +## Parameters + +**Required parameters** + +| Parameter | Type | Description | +| :-- | :-- | :-- | +| [`rules`](#parameter-rules) | array | The Storage Account ManagementPolicies Rules. | + +**Conditional parameters** + +| Parameter | Type | Description | +| :-- | :-- | :-- | +| [`storageAccountName`](#parameter-storageaccountname) | string | The name of the parent Storage Account. Required if the template is used in a standalone deployment. | + +**Optional parameters** + +| Parameter | Type | Description | +| :-- | :-- | :-- | +| [`enableDefaultTelemetry`](#parameter-enabledefaulttelemetry) | bool | Enable telemetry via a Globally Unique Identifier (GUID). | + +### Parameter: `rules` + +The Storage Account ManagementPolicies Rules. + +- Required: Yes +- Type: array + +### Parameter: `storageAccountName` + +The name of the parent Storage Account. Required if the template is used in a standalone deployment. + +- Required: Yes +- Type: string + +### Parameter: `enableDefaultTelemetry` + +Enable telemetry via a Globally Unique Identifier (GUID). + +- Required: No +- Type: bool +- Default: `True` + + +## Outputs + +| Output | Type | Description | +| :-- | :-- | :-- | +| `name` | string | The name of the deployed management policy. | +| `resourceGroupName` | string | The resource group of the deployed management policy. | +| `resourceId` | string | The resource ID of the deployed management policy. | + +## Cross-referenced modules + +_None_ diff --git a/src/carml/v0.6.0/Storage/storage-account/management-policy/main.bicep b/src/carml/v0.6.0/Storage/storage-account/management-policy/main.bicep new file mode 100644 index 00000000..de6c6947 --- /dev/null +++ b/src/carml/v0.6.0/Storage/storage-account/management-policy/main.bicep @@ -0,0 +1,49 @@ +metadata name = 'Storage Account Management Policies' +metadata description = 'This module deploys a Storage Account Management Policy.' +metadata owner = 'Azure/module-maintainers' + +@maxLength(24) +@description('Conditional. The name of the parent Storage Account. Required if the template is used in a standalone deployment.') +param storageAccountName string + +@description('Required. The Storage Account ManagementPolicies Rules.') +param rules array + +@description('Optional. Enable telemetry via a Globally Unique Identifier (GUID).') +param enableDefaultTelemetry bool = true + +resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (enableDefaultTelemetry) { + name: 'pid-47ed15a6-730a-4827-bcb4-0fd963ffbd82-${uniqueString(deployment().name)}' + properties: { + mode: 'Incremental' + template: { + '$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#' + contentVersion: '1.0.0.0' + resources: [] + } + } +} + +resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' existing = { + name: storageAccountName +} + +// lifecycle policy +resource managementPolicy 'Microsoft.Storage/storageAccounts/managementPolicies@2023-01-01' = if (!empty(rules)) { + name: 'default' + parent: storageAccount + properties: { + policy: { + rules: rules + } + } +} + +@description('The resource ID of the deployed management policy.') +output resourceId string = managementPolicy.name + +@description('The name of the deployed management policy.') +output name string = managementPolicy.name + +@description('The resource group of the deployed management policy.') +output resourceGroupName string = resourceGroup().name diff --git a/src/carml/v0.6.0/Storage/storage-account/management-policy/main.json b/src/carml/v0.6.0/Storage/storage-account/management-policy/main.json new file mode 100644 index 00000000..ab33a278 --- /dev/null +++ b/src/carml/v0.6.0/Storage/storage-account/management-policy/main.json @@ -0,0 +1,86 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "metadata": { + "_generator": { + "name": "bicep", + "version": "0.23.1.45101", + "templateHash": "9776092818963506976" + }, + "name": "Storage Account Management Policies", + "description": "This module deploys a Storage Account Management Policy.", + "owner": "Azure/module-maintainers" + }, + "parameters": { + "storageAccountName": { + "type": "string", + "maxLength": 24, + "metadata": { + "description": "Conditional. The name of the parent Storage Account. Required if the template is used in a standalone deployment." + } + }, + "rules": { + "type": "array", + "metadata": { + "description": "Required. The Storage Account ManagementPolicies Rules." + } + }, + "enableDefaultTelemetry": { + "type": "bool", + "defaultValue": true, + "metadata": { + "description": "Optional. Enable telemetry via a Globally Unique Identifier (GUID)." + } + } + }, + "resources": [ + { + "condition": "[parameters('enableDefaultTelemetry')]", + "type": "Microsoft.Resources/deployments", + "apiVersion": "2021-04-01", + "name": "[format('pid-47ed15a6-730a-4827-bcb4-0fd963ffbd82-{0}', uniqueString(deployment().name))]", + "properties": { + "mode": "Incremental", + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [] + } + } + }, + { + "condition": "[not(empty(parameters('rules')))]", + "type": "Microsoft.Storage/storageAccounts/managementPolicies", + "apiVersion": "2023-01-01", + "name": "[format('{0}/{1}', parameters('storageAccountName'), 'default')]", + "properties": { + "policy": { + "rules": "[parameters('rules')]" + } + } + } + ], + "outputs": { + "resourceId": { + "type": "string", + "metadata": { + "description": "The resource ID of the deployed management policy." + }, + "value": "default" + }, + "name": { + "type": "string", + "metadata": { + "description": "The name of the deployed management policy." + }, + "value": "default" + }, + "resourceGroupName": { + "type": "string", + "metadata": { + "description": "The resource group of the deployed management policy." + }, + "value": "[resourceGroup().name]" + } + } +} \ No newline at end of file diff --git a/src/carml/v0.6.0/Storage/storage-account/management-policy/version.json b/src/carml/v0.6.0/Storage/storage-account/management-policy/version.json new file mode 100644 index 00000000..96236a61 --- /dev/null +++ b/src/carml/v0.6.0/Storage/storage-account/management-policy/version.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://aka.ms/bicep-registry-module-version-file-schema#", + "version": "0.4", + "pathFilters": [ + "./main.json" + ] +}