TerraformでDynamoDBのGSI付きテーブル構築
TerraformでDynamoDB構築の続き
DynamoDB GSIをつけて作成する方法
基本は公式ページのここを見ればOK
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dynamodb_table#global_secondary_index
GSIにしたい項目について、attribute 宣言と global_secndary_index宣言をすればいい
code:main.tf
resource "aws_dynamodb_table" "dynamodb" {
name = "Test"
billing_mode = "PROVISIONED"
read_capacity = 20
write_capacity = 20
hash_key = "user_id"
attribute {
name = "user_id"
type = "S"
}
attribute {
name = "gsi_key_ni_sitai_id"
type = "S"
}
global_secondary_index {
name = "index_gsi_key_ni_sitai_id"
hash_key = "gsi_key_ni_sitai_id"
write_capacity = 10
read_capacity = 10
projection_type = "ALL"
}
それぞれの名前は適当に変えつつ、これで terraform init, plan, apply, destroyで動作した