farmer icon indicating copy to clipboard operation
farmer copied to clipboard

Storage Account Lifecycle Policies - Versions

Open mike-wade opened this issue 1 year ago • 4 comments

Hi team,

I would like to add a lifecycle policy to my storage account to delete old versions of my blobs. Is this possible with the current implementation? If so, I haven't worked it out yet.

The following

storageAccount {
    name "storageAccountName"
    enable_versioning [ StorageService.Blobs, true]
    add_lifecycle_rule "delete-old-versions" [Storage.DeleteAfter 30<Days>] Storage.NoRuleFilters
    sku Sku.Standard_GRS
}

Generates this rule:

"policy": {
    "rules": [
      {
        "definition": {
          "actions": {
            "baseBlob": {
              "delete": {
                "daysAfterModificationGreaterThan": 30
              }
            }
          },
          "filters": {
            "blobTypes": [
              "blockBlob"
            ],
            "prefixMatch": []
          }
        },
        "enabled": true,
        "name": "delete-old-versions",
        "type": "Lifecycle"
      }
    ]
  }

As per the Lifecycle Management Overview actions.baseBlob needs to be actions.version but I haven't spotted how this can be specified with the current API.

Thanks in advance

mike-wade avatar Sep 05 '22 10:09 mike-wade

Hi @mike-wade . This looks like a bug then in how Farmer is rendering the ARM out. Probably the code here needs to be adjusted.

isaacabraham avatar Jan 02 '23 01:01 isaacabraham

In fact it's not a bug, it's just that we don't support that feature of lifecycle policies as far as I recall. These look like the main ones we support at the moment. Probably this code needs enhancing and then following the breadcrumbs all the way down to the ARM generation. Doesn't seem like it would be too bad though.

isaacabraham avatar Jan 02 '23 01:01 isaacabraham

@mike-wade I've created a branch, update-blob-lifecycle-management for this. I now remember when I implemented this it was a simple version that intentionally didn't do everything - the hope being that someone would feedback as and when they wanted extra capabilities in it (as you did). Feel free to have a look at the branch, in particular the Adds lifecycle policies correctly test, which shows you how the API will look like to consume. Feedback welcome.

isaacabraham avatar Jan 02 '23 17:01 isaacabraham

@isaacabraham - are we going to go ahead with this enhancement? - will be happy to pick it up

martinbryant avatar Sep 01 '23 10:09 martinbryant