I have the following code which does not take me in azure policy- definition, what I am trying to do is make a definition policy where if the blob tier has not been modified for 30 days, go down to the cool tier and if it has not been modified in 180 becomes tier archive.
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Storage/storageAccounts"
},
{
"field": "kind",
"equals": "BlobStorage"
},
{
"field": "Microsoft.Storage/storageAccounts/accessTier",
"equals": "hot"
}
]
},
"then": {
"effect": "append",
"details": [
{
"field": "Microsoft.Storage/storageAccounts/managementPolicies",
"value": {
"rules": [
{
"enabled": true,
"name": "exampleRule",
"type": "Lifecycle",
"definition": {
"actions": {
"baseBlob": {
"tierToCool": {"daysAfterModificationGreaterThan": 30}
}
}
}
}
]
}
}
]
}
},
"parameters": {}
}
Microsoft.Storage/storageAccounts/managementPolicies
does not exist in Microsoft.Storage
to create a Azure Policy
Alternatively, you can create a StorageAccountPolicy
using PowerShell
to move blobs to the 'Cool' tier if they haven't been modified for 30 days and transition them to the 'Archive' tier if they haven't been modified for 180 days.
$rgName = "<RG_Name>"
$accountName = "<Storage-Account-Name>"
$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction TierToCool -daysAfterModificationGreaterThan 30
Add-AzStorageAccountManagementPolicyAction -InputObject $action `
-BaseBlobAction TierToArchive `
-daysAfterModificationGreaterThan 180
$filter = New-AzStorageAccountManagementPolicyFilter -PrefixMatch blobprefix1,blobprefix2
$rule1 = New-AzStorageAccountManagementPolicyRule -Name "storage-policy" -Action $action -Filter $filter
Set-AzStorageAccountManagementPolicy -ResourceGroupName $rgName -StorageAccountName $accountName -Rule $rule1
Output:
Once ran the above code storage account policy has been created in the Azure portal for a specific storage account.
Reference: Configure a lifecycle management policy