2017-05-30 87 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返回一個一致的從一個請求到另一個請求的順序,這應該工作。