Skip to content

feat: DynamoDB single-table Terraform module with 5 GSIs - #64

Open
maxsonferovante wants to merge 4 commits into
mainfrom
feature/single-table-dynamodb
Open

feat: DynamoDB single-table Terraform module with 5 GSIs#64
maxsonferovante wants to merge 4 commits into
mainfrom
feature/single-table-dynamodb

Conversation

@maxsonferovante

Copy link
Copy Markdown
Contributor

Summary

Creates Terraform module for DynamoDB single-table design with 5 Global Secondary Indexes.

Changes

  • New module:
    • : Table with composite key design + 5 GSIs
    • : Configurable table name and billing
    • : Table ARN and GSI attributes
  • Dev environment: Updated to use single_table module

GSI Design

Index Key Schema Access Pattern
GSI1 PK: UUID, SK: CERT# Certificate by ID
GSI2 PK: email, SK: ENTITY# Orders, Certs, Participants by email
GSI3 PK: product, SK: ENTITY# Products, Certs, Orders by product
GSI4 PK: SUCCESS#Y/N, SK: CERT# Successful certificates
GSI5 PK: CITY#name, SK: PART# Participants by city

Related

API PR: PythonFloripa/py-certify-api
Notification PR: PythonFloripa/py-certify-notification

- Create single_table module with composite key design:
  - PK/SK as main access pattern
  - GSI1: UUID-based lookups (Certificate by ID)
  - GSI2: Email-based access (Orders, Certificates, Participants)
  - GSI3: Product-based access (Products, Certificates, Orders)
  - GSI4: Success flag access (successful certificates)
  - GSI5: City-based access (Participants)
- Update dev environment to use single_table module
- Replace 4 separate DynamoDB tables with single table design
bentoluizv
bentoluizv previously approved these changes Sep 7, 2026

@bentoluizv bentoluizv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O outputs.tf não foi atualizado junto — ainda referencia os quatro módulos que esse PR removeu do main.tf. Rodei terraform validate no head da branch e dá 8 erros de "Reference to undeclared module", nas linhas 15, 20, 26, 31, 37, 42, 48 e 53. Precisa remover esses outputs ou apontar pro module.dynamodb_single_table.


# EntityType para identificação rápida do tipo
attribute {
name = "EntityType"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O EntityType tá declarado como attribute mas não é chave de nada — nem hash_key/range_key da tabela, nem de nenhum dos cinco GSIs. Isso quebra o apply no plan, antes de chamar a AWS:

Error: all attributes must be indexed. Unused attributes: ["EntityType"]
  on ../modules/02.dynamodb/single_table/main.tf line 14

Testei o módulo contra o MiniStack variando só esse bloco: com ele dá o erro acima, sem ele a tabela sobe ACTIVE com os 5 GSIs certinhos.

Pode remover — o DynamoDB é schemaless, então a aplicação continua gravando EntityType e usando no filter_expression sem precisar declarar como atributo.


# GSI5: CITY# lookups (participant city)
global_secondary_index {
name = "GSI5"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O GSI5 reintroduz o índice por cidade removido no #59. Dá pra tirar ele e os atributos GSI5PK/GSI5SK (:72 e :77)?

@bentoluizv
bentoluizv dismissed their stale review September 7, 2026 20:33

revisei errado

- Remove GSI5 (city-based access for participants)
- Update outputs.tf to reference dynamodb_single_table module
- Fix terraform validate errors (8 module reference errors)
- Update comments to reflect actual GSI usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants