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

如何禁用GCS存储桶软删除功能?UI及Terraform无相关选项

禁用GCS存储桶软删除的方法

以下是几种可行的禁用方式,覆盖CLI、API和Terraform场景:

1. 通过gcloud CLI操作

执行命令替换目标存储桶名称即可完成禁用:

gcloud storage buckets update gs://<你的存储桶名称> --soft-delete-delete

2. 通过REST API操作

发送PATCH请求清除存储桶的软删除配置,需携带有效的访问令牌:

PATCH https://storage.googleapis.com/storage/v1/b/<你的存储桶名称>?fields=softDelete
Authorization: Bearer <你的访问令牌>
Content-Type: application/json

{
  "softDelete": null
}

可通过gcloud auth print-access-token命令获取访问令牌。

3. 通过Terraform操作(需更新Provider版本)

确保你的HashiCorp Google Provider版本在4.72.0及以上,在存储桶资源中添加软删除禁用配置:

resource "google_storage_bucket" "your_bucket" {
  name          = "你的存储桶名称"
  location      = "你的存储桶区域"
  # 其他原有配置...

  soft_delete_config {
    mode = "DISABLED"
  }
}

先执行terraform init -upgrade升级Provider,再运行terraform apply使配置生效。

注意:禁用软删除后,已有的软删除对象仍会遵循原保留期到期后永久删除,后续删除的对象将直接被永久删除。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 18:10:00