Azure Storage Management Policy
This page shows how to write Terraform and Azure Resource Manager for Storage Management Policy and write them securely.
azurerm_storage_management_policy (Terraform)
The Management Policy in Storage can be configured in Terraform with the resource name azurerm_storage_management_policy. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_storage_management_policy" "move_to_cold" {
storage_account_id = var.storage_account_id
rule {
name = "moveToCold"
enabled = true
resource "azurerm_storage_management_policy" "example" {
storage_account_id = azurerm_storage_account.example.id
rule {
name = "global-policy"
enabled = true
filters {
resource "azurerm_storage_management_policy" "life_cycle_management" {
count = var.enable_remote_state ? 1 : 0
storage_account_id = azurerm_storage_account.terraform_storage_account.*.id[0]
rule {
name = "terraformstateexpiration"
resource "azurerm_storage_management_policy" "upload" {
storage_account_id = azurerm_storage_account.files.id
rule {
name = "cleanUploads"
enabled = true
resource "azurerm_storage_management_policy" "claim-check-example-storage-management-policy" {
storage_account_id = azurerm_storage_account.storage-account.id
rule {
name = "data-retention"
enabled = true
resource "azurerm_storage_management_policy" "example" {
storage_account_id = azurerm_storage_account.example.id
rule {
name = "rule1"
enabled = true
resource "azurerm_storage_management_policy" "products" {
storage_account_id = azurerm_storage_account.products.id
rule {
name = "removeTemporaryBlobs"
enabled = true
resource "azurerm_storage_management_policy" "life_cycle_management" {
count = var.enable_remote_state ? 1 : 0
storage_account_id = azurerm_storage_account.terraform_storage_account.*.id[0]
rule {
name = "terraformstateexpiration"
resource "azurerm_storage_management_policy" "move_to_cold" {
storage_account_id = var.storage_account_id
rule {
name = "moveToCold"
enabled = true
resource "azurerm_storage_management_policy" "mgmt_policy" {
storage_account_id = var.storage_account_id
dynamic "rule" {
for_each = var.settings.rules
Parameters
-
idoptional computed - string -
storage_account_idrequired - string -
rulelist block-
enabledrequired - bool -
namerequired - string -
actionslist block-
base_bloblist block-
delete_after_days_since_modification_greater_thanoptional - number -
tier_to_archive_after_days_since_modification_greater_thanoptional - number -
tier_to_cool_after_days_since_modification_greater_thanoptional - number
-
-
snapshotlist block-
delete_after_days_since_creation_greater_thanoptional - number
-
-
-
filterslist block-
blob_typesoptional - set of string -
prefix_matchoptional - set of string
-
-
-
timeoutssingle block
Explanation in Terraform Registry
Manages an Azure Storage Account Management Policy.
Tips: Best Practices for The Other Azure Storage Resources
In addition to the azurerm_storage_account, Azure Storage has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_storage_account
Ensure to use HTTPS connections
It is better to use HTTPS instead of HTTP, which could be vulnerable to person-in-the-middle attacks.
azurerm_storage_account_network_rules
Ensure to allow Trusted Microsoft Services to bypass
It is better to allow Trusted Microsoft Services to bypass. They are not able to access storage account unless rules are set to allow them explicitly.
Microsoft.Storage/storageAccounts/managementPolicies (Azure Resource Manager)
The storageAccounts/managementPolicies in Microsoft.Storage can be configured in Azure Resource Manager with the resource name Microsoft.Storage/storageAccounts/managementPolicies. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
apiVersionrequired - stringnamerequired - stringThe name of the Storage Account Management Policy. It should always be 'default'
propertiesoptionalpolicyrequiredrulesrequired arraydefinitionrequiredactionsrequiredbaseBloboptionaldeleteoptionaldaysAfterLastAccessTimeGreaterThanoptional - numberValue indicating the age in days after last blob access. This property can only be used in conjunction with last access time tracking policy
daysAfterModificationGreaterThanoptional - numberValue indicating the age in days after last modification
enableAutoTierToHotFromCooloptional - booleanThis property enables auto tiering of a blob from cool to hot on a blob access. This property requires tierToCool.daysAfterLastAccessTimeGreaterThan.
tierToArchiveoptionaldaysAfterLastAccessTimeGreaterThanoptional - numberValue indicating the age in days after last blob access. This property can only be used in conjunction with last access time tracking policy
daysAfterModificationGreaterThanoptional - numberValue indicating the age in days after last modification
tierToCooloptionaldaysAfterLastAccessTimeGreaterThanoptional - numberValue indicating the age in days after last blob access. This property can only be used in conjunction with last access time tracking policy
daysAfterModificationGreaterThanoptional - numberValue indicating the age in days after last modification
snapshotoptionaldeleteoptionaldaysAfterCreationGreaterThanrequired - numberValue indicating the age in days after creation
tierToArchiveoptionaldaysAfterCreationGreaterThanrequired - numberValue indicating the age in days after creation
tierToCooloptionaldaysAfterCreationGreaterThanrequired - numberValue indicating the age in days after creation
versionoptionaldeleteoptionaldaysAfterCreationGreaterThanrequired - numberValue indicating the age in days after creation
tierToArchiveoptionaldaysAfterCreationGreaterThanrequired - numberValue indicating the age in days after creation
tierToCooloptionaldaysAfterCreationGreaterThanrequired - numberValue indicating the age in days after creation
filtersoptionalblobIndexMatchoptional arraynamerequired - stringThis is the filter tag name, it can have 1 - 128 characters
oprequired - stringThis is the comparison operator which is used for object comparison and filtering. Only == (equality operator) is currently supported
valuerequired - stringThis is the filter tag value field used for tag based filtering, it can have 0 - 256 characters
blobTypesrequired - arrayAn array of predefined enum values. Currently blockBlob supports all tiering and delete actions. Only delete actions are supported for appendBlob.
prefixMatchoptional - arrayAn array of strings for prefixes to be match.
enabledoptional - booleanRule is enabled if set to true.
namerequired - stringA rule name can contain any combination of alpha numeric characters. Rule name is case-sensitive. It must be unique within a policy.
typerequired - stringThe valid value is Lifecycle
typerequired - string
Frequently asked questions
What is Azure Storage Management Policy?
Azure Storage Management Policy is a resource for Storage of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Storage Management Policy?
For Terraform, the sal12oni/aws_azure_migration, thecomalley/homelab-remote-backup and tmeadon/clippings source code examples are useful. See the Terraform Example section for further details.