2017-05-30 54 views
0

我在TerraformTerraform DynamoDB指数环

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在他们的DOC说:的DynamoDB API预计属性结构(名称和类型)创建或更新GSI/LSI的时候一起传递或创建初始表。在这些情况下,它期望提供哈希/范围键;因为这些地方会在许多地方被重复使用(即表格的范围键可以是一个或多个GSI的一部分),它们被存储在表格对象上以防止重复并增加一致性。如果您在这里添加未在这些场景中使用的属性,则可能会导致规划中出现无限循环。但我不认为我的配置与此相关。任何类似的经历?我怀疑与this有关系。谢谢!

回答

1

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

看来这是这种情况的一个例子。在配置中,non_key_attributes被列为["vpc_id", "instance_id", "integration_id", "private_ip"],但它们从API返回为["vpc_id", "instance_id", "private_ip", "integration_id"]

这是Terraform中的一个错误,它不会将这两个视为等同的,如果确实(因为它看起来)排序不敏感并且DynamoDB API可以以与提交不同的顺序返回它们。

作为解决此问题的一个解决方法,它可能会重新排列config中的列表以匹配API返回的内容,这会导致Terraform不再看到差异。只要API返回一个一致的从一个请求到另一个请求的顺序,这应该工作。