Automate deployment of Storage account Life Cycle Management policy

Pratim Das, Partha C 346 Reputation points
2025-02-07T04:27:44.5566667+00:00

Hi Team,

I have manually created one storage lifecycle management rule manually from portal

User's image

I need to put it in a devops pileline. I need different policies for different containers within the storage account. Which means when new container gets created I'll apply a policy to it without affecting other containers and policies.

How to achieve that? Please help.

Regards,

Partha

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,361 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,067 questions
{count} votes

Accepted answer
  1. Nandamuri Pranay Teja 805 Reputation points Microsoft Vendor
    2025-02-07T10:08:51.8333333+00:00

    Hello Pratim Das, Partha C

    Welcome to Microsoft Q&A, thanks for posting your query.

    To facilitate the automation of Azure Storage Lifecycle Management rules for various containers within a storage account through a DevOps pipeline, the Below following steps can be implemented. This approach enables the application of designated lifecycle management rules to newly established containers while ensuring that existing containers remain unaffected.

    1. Ensure you have the lifecycle management rules defined. You can create a JSON file that contains the rules for each container.
    2. You can use Azure DevOps to create a pipeline that will apply these lifecycles management rules when a new container is created.
    3. Create a new pipeline in Azure DevOps.
    4. Choose the appropriate repository where your JSON file and scripts are stored.
    5. You can use Azure Event Grid to trigger your pipeline when a new container is created. Set up an Event Grid subscription for the storage account that listens for the Microsoft.Storage.BlobCreated event.
    6. You can use Azure CLI or PowerShell to create a script that applies the lifecycle management rules to the newly created container
    7. Test Your Pipeline Create a new container in your Azure Storage Account. Verify that the Event Grid triggers the pipeline. Check that the appropriate lifecycle management rule is applied to the new container without affecting existing containers.
    8. Monitor the pipeline runs to ensure that lifecycle management rules are being applied correctly.
    9. Update your scripts and rules as needed based on changes in requirements.

    Please let us know if you have any further queries. I’m happy to assist you further.

    References: https://learn.microsoft.com/en-us/azure/storage/blobs/lifecycle-management-policy-configure?tabs=azure-portal#create-or-manage-a-policy

    Please do consider to “up-vote” wherever the information provided helps you, this can be beneficial to other community members. 

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.