azure 如何将Blob生命周期规则添加到ARM模板

ffdz8vbo  于 2022-12-14  发布在  其他
关注(0)|答案(2)|浏览(164)

我已经根据现有的资源组创建了一个ARM模板,
最近我在我的帐户存储中添加了一个新的配置到我的blob存储中,我需要管理它的生命周期,幸运的是,通过添加一个规则,Azure Portal上提供了这个配置:

或者添加以下json代码:

{
  "rules": [
    {
      "name": "ruleFoo",
      "enabled": true,
      "type": "Lifecycle",
      "definition": {
        "filters": {
          "blobTypes": [ "blockBlob" ],
          "prefixMatch": [ "container1/foo" ]
        },
        "actions": {
          "baseBlob": {
            "tierToCool": { "daysAfterModificationGreaterThan": 30 },
            "tierToArchive": { "daysAfterModificationGreaterThan": 90 },
            "delete": { "daysAfterModificationGreaterThan": 2555 }
          },
          "snapshot": {
            "delete": { "daysAfterCreationGreaterThan": 90 }
          }
        }
      }
    }
  ]
}

但我不清楚的是在我的blob服务部分的哪个部分

{
            "type": "Microsoft.Storage/storageAccounts/blobServices",
            "apiVersion": "[variables('storageAccount_version')]",
            "name": "[concat(variables('storageAccount_name'), '/default')]",
            "tags": {
                "displayName": "Storage Account - Blob Service"
            },
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccount_name'))]"
            ],
            "properties": {
                "cors": {
                    "corsRules": []
                },
                "deleteRetentionPolicy": {
                    "enabled": false
                }
            }
        },

我会感激任何帮助!谢谢!

vlju58qv

vlju58qv1#

以下模板创建存储帐户及其Blob生命周期。
关键是使用存储帐户名称前缀命名生命周期资源,并添加dependsOn部分。

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "storageAccountName": {
            "type": "string",
            "defaultValue": "ajstoragetest444"
        }
    },
    "resources": [
        {
            "name": "[parameters('storageAccountName')]",
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2019-06-01",
            "location": "westeurope",
            "sku": {
                "name": "Standard_LRS",
                "tier": "Standard"
            },
            "kind": "StorageV2",
            "properties": {
            }
        },
        {
            "name": "[concat(parameters('storageAccountName'), '/default')]",
            "type": "Microsoft.Storage/storageAccounts/managementPolicies",
            "apiVersion": "2019-06-01",
            "dependsOn": [
                "[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
            ],
            "properties": {
                "policy": {
                    "rules": [
                        {
                            "name": "ruleFoo",
                            "enabled": true,
                            "type": "Lifecycle",
                            "definition": {
                                "filters": {
                                    "blobTypes": [
                                        "blockBlob"
                                    ],
                                    "prefixMatch": [
                                        "container1/foo"
                                    ]
                                },
                                "actions": {
                                    "baseBlob": {
                                        "tierToCool": {
                                            "daysAfterModificationGreaterThan": 30
                                        },
                                        "tierToArchive": {
                                            "daysAfterModificationGreaterThan": 90
                                        },
                                        "delete": {
                                            "daysAfterModificationGreaterThan": 2555
                                        }
                                    },
                                    "snapshot": {
                                        "delete": {
                                            "daysAfterCreationGreaterThan": 90
                                        }
                                    }
                                }
                            }
                        }
                    ]
                }
            }
        }
    ]
}
qjp7pelc

qjp7pelc2#

请阅读本文,并注意下面示例中的name: default,这是storageAccounts/managementPolicies唯一允许的名称:

{
  "name": "default",
  "type": "Microsoft.Storage/storageAccounts/managementPolicies",
  "apiVersion": "2019-04-01",
  "properties": {
    "policy": {
      "rules": [
        {
          "enabled": "boolean",
          "name": "string",
          "type": "Lifecycle",
          "definition": {
            "actions": {
              "baseBlob": {
                "tierToCool": {
                  "daysAfterModificationGreaterThan": "number"
                },
                "tierToArchive": {
                  "daysAfterModificationGreaterThan": "number"
                },
                "delete": {
                  "daysAfterModificationGreaterThan": "number"
                }
              },
              "snapshot": {
                "delete": {
                  "daysAfterCreationGreaterThan": "number"
                }
              }
            },
            "filters": {
              "prefixMatch": [
                "string"
              ],
              "blobTypes": [
                "string"
              ]
            }
          }
        }
      ]
    }
  }
}

相关问题