# Azure Storage Account Missing Lifecycle Policy

> Checks storage accounts with no blob lifecycle policy; no finding is raised until blob age is measured, and none is ever priced from total capacity.

Source: https://zop.dev/integrations/azure/recommendations/azure-storage-account-missing-lifecycle-policy

---

## What a lifecycle policy does that a tier setting cannot

The account's default access tier applies to every blob at once. A lifecycle policy works blob by
blob. The [lifecycle management overview](https://learn.microsoft.com/en-us/azure/storage/blobs/lifecycle-management-overview)
describes rules that move current versions, previous versions and snapshots to cooler tiers when
they have not been accessed or modified for a period, and that delete them at the end of their life.
Conditions can use creation time, last modified time, or last access time if access tracking is on.

Microsoft states that lifecycle policies are free; you pay the normal Set Blob Tier operation
charges, and deletes are free. Without a policy, logs, backups and exports written years ago keep
billing at whatever tier they were written in.

## Checking whether an account has a policy

```bash
az storage account management-policy show \
  --resource-group my-rg --account-name mystorageacct
```

An error saying no policy exists means the account has none. To see how much data each tier holds,
read the `BlobCapacity` metric split by its `Tier` dimension:

```bash
az monitor metrics list \
  --resource <storage-account-resource-id>/blobServices/default \
  --metric BlobCapacity --dimension Tier --aggregation Average --interval PT24H --offset 7d
```

## Which accounts are candidates

ZopNight treats an account as missing a policy only when Azure explicitly reports that no
management policy exists. A transient error while reading the policy is not taken as "no policy",
so the account is simply not evaluated that round. This check is not live yet: even a confirmed
candidate gets no finding today, for the reason below.

## Why candidates do not yet carry a dollar figure

The real saving is the Hot data old enough for a rule to move, multiplied by the gap between the
Hot rate and the cooler tier's rate. Tier capacity is easy to read, but it only says how much is
Hot, not how much of it is old. Azure has no metric for blob age; the authoritative source is a
[blob inventory report](https://learn.microsoft.com/en-us/azure/storage/blobs/blob-inventory),
a daily or weekly CSV or Parquet file listing every blob with its creation time and other
properties. Treating all Hot capacity as old would overstate the saving, so ZopNight neither lists
the account nor raises a recommendation until age-eligible volume is measured.

Once this check is live, it and
<a href="https://zop.dev/integrations/azure/recommendations/azure-storage-account-hot-tier-with-low-access">Azure Storage Account Hot Tier with Low Access</a>
could apply to the same account, but they are separate levers: that one prices an account-wide switch
from real transaction data, and this one will price only aged blobs, so the saving is not counted
twice.

## What the saving would look like

```text
monthly saving = Hot GB older than the rule's age threshold
                 x (Hot rate - target tier rate) x 730
                 capped at the account's monthly cost
```

## Adding a lifecycle policy

1. Decide the ages that suit your data, for example Cool after 30 days without modification and
   Archive after 180, and whether anything should be deleted.
2. Write the rules to `policy.json` and apply them:
   `az storage account management-policy create --resource-group my-rg --account-name mystorageacct --policy @policy.json`.
3. Allow up to 24 hours for the first run; Microsoft notes new or edited rules can take that long
   to take effect.

**Warning**
Cooler tiers carry minimum storage periods: Microsoft lists 30 days for Cool, 90 for Cold and 180 for Archive, with early deletion charges if a blob is moved or deleted sooner. Archive blobs also have to be rehydrated before they can be read.
