TerraformでDynamoDBのGSI付きテーブル構築
基本は公式ページのここを見ればOK
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で動作した