Skip to content

Commit

Permalink
Add Storage Account Management Policy module
Browse files Browse the repository at this point in the history
  • Loading branch information
sebassem committed Dec 6, 2023
1 parent 14d1532 commit d0ef787
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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_
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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]"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://aka.ms/bicep-registry-module-version-file-schema#",
"version": "0.4",
"pathFilters": [
"./main.json"
]
}

0 comments on commit d0ef787

Please sign in to comment.