Terraform dynamodb 错误 - 必须对所有属性建立索引

Cha*_*Zee 1 amazon-web-services amazon-dynamodb terraform

我正在尝试使用以下 terraform 资源模块创建一个简单的 dynamodb 表。

运行 terraform 时出现以下错误: 必须对所有属性建立索引。未使用的属性:[“pactitle”“ipadress”“Timestamp”]。 为什么我们需要索引所有属性?如何解决这个问题?

resource "aws_dynamodb_table" "this" {
  count = var.create_table ? 1 : 0

  name             = var.name
  billing_mode     = var.billing_mode
  hash_key         = var.hash_key
  range_key        = var.range_key
  read_capacity    = var.read_capacity
  write_capacity   = var.write_capacity
  //stream_enabled   = var.stream_enabled
  //stream_view_type = var.stream_view_type

  dynamic "attribute" {
    for_each = var.attributes

    content {
      name = attribute.value.name
      type = attribute.value.type
    }
  }


  server_side_encryption {
    enabled     = var.server_side_encryption_enabled
    kms_key_arn = var.server_side_encryption_kms_key_arn
  }

  tags = merge(
    var.tags,
    {
      "Name" = format("%s", var.name)
    },
  )

  timeouts {
    create = lookup(var.timeouts, "create", null)
    delete = lookup(var.timeouts, "delete", null)
    update = lookup(var.timeouts, "update", null)
  }
}
Run Code Online (Sandbox Code Playgroud)

调用模块


module "dynamodb_table" {

source = "./../../../modules/dynamodb"
 

  name      = "pack-audit-cert"
  hash_key  = "id"
  create_table= true
  read_capacity=5
  write_capacity=5
  billing_mode   = "PROVISIONED"


 range_key = "pacid"

  attributes = [
    {
      name = "id"
      type = "N"
    },
    {
      name = "pacid"
      type = "S"
    },
    {
      name = "pactitle"
      type = "S"
    },
    {
      name = "ipadress"
      type = "S"
    },
    {
      name = "Timestamp"
      type = "S"
    }
  ]


}
Run Code Online (Sandbox Code Playgroud)

谢谢

Mar*_*k B 8

该错误消息有点误导。您应该仅在创建表时定义索引属性。由于 DynamoDB 是无模式数据库,因此它在创建表时不关心其他属性。