Maxim Vershinin
Maxim Vershinin

Reputation: 643

How in terraform dynamodb specify composite primary key (hashkey)

My goal is to create terraform resource "aws_dynamodb_table" with composite primary key as it describes in AWS documentation.

Based on Terraform documentation it allows for hash_key to have only a single Attribute name. How can I have a hash_key made by multiple attributes?

Upvotes: 4

Views: 6947

Answers (1)

Daniel Montoya
Daniel Montoya

Reputation: 76

Use the range_key terraform argument, which is the sort key on DynamoDB. That way you'll get a composite key as stated in the AWS documentation. The hash_key is referred as Partition key.

Partition key and sort key – Referred to as a composite primary key, this type of key is composed of two attributes. The first attribute is the partition key, and the second attribute is the sort key.

If you want to query among other attributes, try with a local_secondary_index.

Upvotes: 6

Related Questions