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

如何在Terraform中为AWS DynamoDB主表及副本开启删除保护?

为DynamoDB全局表的主表和副本表开启删除保护

要让副本表也启用删除保护,只需在replica动态块的内容里添加deletion_protection_enabled = true配置即可。注意需要确保你的AWS Terraform Provider版本不低于v4.67.0(该版本开始支持副本表的删除保护参数)。

修改后的完整代码如下:

主资源配置(main.tf)

resource "aws_dynamodb_table" "default" {
  name = "example"

  # 此处保留你的其他基础配置(如属性定义、主键、读写容量模式等)...

  # 主表开启删除保护
  deletion_protection_enabled = true

  dynamic "replica" {
    for_each = var.replica_regions

    content {
      region_name                = replica.value.region_name
      # 为每个副本表开启删除保护
      deletion_protection_enabled = true
    }
  }
}

变量配置(variable.tf)

variable "replica_regions" {
  description = "为全局DynamoDB表创建副本的区域名称列表"
  type        = list(map(string))
  default     = []
}

补充说明

  • 主表的deletion_protection_enabled参数仅控制主表的删除保护状态,每个副本表的保护状态需要单独在对应的replica块内配置。
  • 若未指定Provider版本,建议在versions.tf中明确兼容版本:
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 4.67.0"
    }
  }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 03:22:06