You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Terraform为Azure存储账户配置排除指定容器的保留策略

解决方案

问题原因

Terraform AzureRM provider的存储管理策略(azurerm_storage_management_policy)不支持通过prefix_match !=这种否定语法排除路径,prefix_match仅用于定义需要包含的Blob前缀。要实现排除特定容器/文件夹的需求,需使用官方提供的exclude_prefix参数。

修正后的代码

将你代码中错误的prefix_match !=替换为exclude_prefix,同时移除无效的否定语法,即可实现“匹配所有Blob,排除指定路径”的逻辑:

storage_account_id = azurerm_storage_account.example.id

rule {
  name    = "rule2"
  enabled = true
  filters {
    exclude_prefix = ["container1/folder1", "container2/folder2"]
    blob_types     = ["blockBlob"]
  }
  actions {
    base_blob {
      tier_to_cool_after_days_since_modification_greater_than    = 11
      tier_to_archive_after_days_since_modification_greater_than = 51
      delete_after_days_since_modification_greater_than          = 101
    }
    snapshot {
      change_tier_to_archive_after_days_since_creation = 90
      change_tier_to_cool_after_days_since_creation    = 23
      delete_after_days_since_creation_greater_than    = 31
    }
    version {
      change_tier_to_archive_after_days_since_creation = 9
      change_tier_to_cool_after_days_since_creation    = 90
      delete_after_days_since_creation                 = 3
    }
  }
}

核心说明

  • exclude_prefix:用于指定需要排除的Blob路径前缀,支持多个条目,格式为容器名/文件夹名,会匹配该路径下所有Blob(包括子文件夹内容)
  • 未指定prefix_match时,规则默认覆盖存储账户内所有符合blob_types的Blob,再通过exclude_prefix剔除不需要应用策略的路径
  • 路径匹配为前缀匹配,确保exclude_prefix的路径书写准确(区分大小写,与存储容器/文件夹名称完全一致)

内容的提问来源于stack exchange,提问作者Izzy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 23:43:31