Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
764 views
in Technique[技术] by (71.8m points)

Terraform + DynamoDB: All attributes must be indexed

I want to create a Terraform configuration for DynamoDB table with multiple (> 10) attributes. And I have no need to add all attributes as an index to global_secondary_index or local_secondary_index. But when I run terraform plan command I have next error:

All attributes must be indexed. Unused attributes: ...

I found the validation check in the Terraform repository in validateDynamoDbTableAttributes function.

But also as I know the best practice is that each table in DynamoDB is limited to a maximum of five global secondary indexes and five local secondary indexes from General Guidelines for Secondary Indexes in DynamoDB.

And since I have more than 10 attributes it looks like a problem to me.

What I would like to understand why all attributes must be indexed and what to do in case if you have a big number of attributes.

Thanks!

question from:https://stackoverflow.com/questions/50006885/terraform-dynamodb-all-attributes-must-be-indexed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You do not have to define every attribute you want to use up front when creating your table.

attribute blocks inside aws_dynamodb_table resources are not defining which attributes you can use in your application. They are defining the key schema for the table and indexes.

For example, the following Terraform defines a table with only a hash key:

resource "aws_dynamodb_table" "test" {
  name           = "test-table-name"
  read_capacity  = 10
  write_capacity = 10
  hash_key       = "Attribute1"

  attribute {
    name = "Attribute1"
    type = "S"
  }
}

Every item in this table has Attribute1, but you can create additional attributes with your application Two items, both have Attribute1, but differing custom attributes

This means that you can have your 10+ attributes as long as you don't need to define them in an AttributeDefinition, and since you say you don't need them to be indexed, you'll be fine.

For some discussion of the confusion (attribute is confusing and doesn't match the DynamoDB API), see this pull request.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...