Azure Storage Accounts have lifecycle management policies which help with following:
- Transition blobs from cool to hot
- Transition blobs, blob versions, and blob snapshots to a cooler storage tier if these objects have not been accessed or modified for a period, to optimize for cost. The objects can be moved from hot to cool, from hot to archive, or from cool to archive.
- Delete blobs, blob versions, and blob snapshots at the end of their lifecycles.
- Apply rules to containers or to a subset of blobs, using name prefixes or blob index tags as filters.
Example of a rule could be:
- Any files where the modified date is older than 90 days will be changed to the Cool tier.
- Any files where the modified date is older than 180 days will be changed to the Archive tier.
- Delete files older than 365 days.
If the condition to move a blob is based on last accessed time you need to enable last access time tracking https://learn.microsoft.com/en-us/azure/templates/microsoft.storage/2021-02-01/storageaccounts/blobservices?tabs=json&pivots=deployment-language-terraform
The rules translate to a JSON format. So once you create the rule through the portal get the JSON from the code view and you can use PowerShell/Terraform(https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_management_policy) to apply to other storage accounts.
For optimising current storage accounts, you can run PowerShell or use Terraform to update the policies.
For governance purposes any new storage accounts being created should have these policies enabled (https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_management_policy)
Useful links:
https://learn.microsoft.com/en-us/azure/storage/blobs/lifecycle-management-overview
Please do let me know if this makes sense for your scenario or any additional questions you might have.