Amazon dynamodb 地形发电机索引环

Amazon dynamodb 地形发电机索引环,amazon-dynamodb,terraform,Amazon Dynamodb,Terraform,我在Terraform中有以下配置 resource "aws_dynamodb_table" "scanner" { name = "scanner" read_capacity = 2 write_capacity = 1 hash_key = "public_ip" attribute { name = "public_ip" type = "S" } attribute { name = "region" type = "S" } attribute {

我在Terraform中有以下配置

resource "aws_dynamodb_table" "scanner" {
name = "scanner"
read_capacity = 2
write_capacity = 1
hash_key = "public_ip"
attribute {
    name = "public_ip"
    type = "S"
}
attribute {
    name = "region"
    type = "S"
}
attribute {
    name = "account_id"
    type = "N"
}
global_secondary_index {
    name = "cleanup-index"
    hash_key = "account_id"
    range_key = "region"
    read_capacity = 1
    write_capacity = 1
    projection_type = "INCLUDE"
    non_key_attributes = ["vpc_id", "instance_id", "integration_id", "private_ip"]
}
}
在我从Terraform 0.7.13升级到0.9.6之前,它工作得非常完美。此后,Terraform每次都会尝试重新创建索引:

~ aws_dynamodb_table.scanner
global_secondary_index.3508752412.hash_key:             "" => "account_id"
global_secondary_index.3508752412.name:                 "" => "cleanup-index"
global_secondary_index.3508752412.non_key_attributes.#: "0" => "4"
global_secondary_index.3508752412.non_key_attributes.0: "" => "vpc_id"
global_secondary_index.3508752412.non_key_attributes.1: "" => "instance_id"
global_secondary_index.3508752412.non_key_attributes.2: "" => "integration_id"
global_secondary_index.3508752412.non_key_attributes.3: "" => "private_ip"
global_secondary_index.3508752412.projection_type:      "" => "INCLUDE"
global_secondary_index.3508752412.range_key:            "" => "region"
global_secondary_index.3508752412.read_capacity:        "" => "1"
global_secondary_index.3508752412.write_capacity:       "" => "1"
global_secondary_index.3860163270.hash_key:             "account_id" => ""
global_secondary_index.3860163270.name:                 "cleanup-index" => ""
global_secondary_index.3860163270.non_key_attributes.#: "4" => "0"
global_secondary_index.3860163270.non_key_attributes.0: "vpc_id" => ""
global_secondary_index.3860163270.non_key_attributes.1: "instance_id" => ""
global_secondary_index.3860163270.non_key_attributes.2: "private_ip" => ""
global_secondary_index.3860163270.non_key_attributes.3: "integration_id" => ""
global_secondary_index.3860163270.projection_type:      "INCLUDE" => ""
global_secondary_index.3860163270.range_key:            "region" => ""
global_secondary_index.3860163270.read_capacity:        "1" => "0"
global_secondary_index.3860163270.write_capacity:       "1" => "0"

Terraform在其文档中说:DynamoDB API希望在创建或更新GSI/LSI或创建初始表时传递属性结构(名称和类型)。在这些情况下,它期望提供散列/范围键;因为它们在许多地方重复使用(即表的范围键可以是一个或多个GSI的一部分),所以它们存储在表对象上以防止重复并提高一致性。如果在此处添加在这些场景中未使用的属性,则可能会导致规划中出现无限循环。但我认为我的配置与此无关。有类似的经历吗?我怀疑他和我有关系。谢谢

有时底层的提供者API会对Terraform提交的数据进行规范化或重构,以便在读回数据时数据会有所不同

这似乎就是这种情况的一个例子。在配置中,
非密钥属性
被列为
[“专有网络id”、“实例id”、“集成id”、“私有ip”]
,但它们从API返回为
[“专有网络id”、“实例id”、“私有ip”、“集成id”]

Terraform中的一个缺陷是,它不认为这两个是等效的,如果排序确实不敏感,DynamoDB API可以以与提交不同的顺序返回它们

作为一种解决方法,在修复此错误之前,可以在配置中重新排序列表以匹配API返回的内容,这将导致Terraform不再看到差异。只要API以从一个请求到下一个请求的一致顺序返回列表,这项工作就应该有效