dynamodb
Creates one or more DynamoDB tables with encryption, point-in-time recovery, optional streams, GSIs, LSIs, and Application Auto Scaling for provisioned capacity tables.
Supports both PAY_PER_REQUEST and PROVISIONED billing modes. Tables in PROVISIONED mode can opt into read/write auto scaling with configurable min/max capacity and target utilization.
Usage
module "dynamodb" {
source = "hcassc.jfrog.io/iac-terraform-modules-virtual/database/dynamodb/aws"
version = "0.1.0"
tables = {
orders = {
name = "prod-orders"
hash_key = "order_id"
range_key = "created_at"
attributes = [
{ name = "order_id", type = "S" },
{ name = "created_at", type = "S" },
{ name = "customer_id", type = "S" },
]
global_secondary_indexes = [
{
name = "CustomerIndex"
hash_key = "customer_id"
projection_type = "ALL"
},
]
kms_key_arn = module.kms.key_arn
point_in_time_recovery = true
stream_enabled = true
stream_view_type = "NEW_AND_OLD_IMAGES"
}
sessions = {
name = "prod-sessions"
billing_mode = "PROVISIONED"
read_capacity = 10
write_capacity = 5
hash_key = "session_id"
attributes = [
{ name = "session_id", type = "S" },
]
ttl_attribute = "expires_at"
kms_key_arn = module.kms.key_arn
autoscaling = {
read_min_capacity = 10
read_max_capacity = 100
write_min_capacity = 5
write_max_capacity = 50
target_utilization = 70
}
}
}
tags = {
Environment = "prod"
Team = "platform"
}
}
Requirements
| Name | Version |
|---|---|
| terraform | ~> 1.5 |
| aws | ~> 6.50 |
Providers
| Name | Version |
|---|---|
| aws | 6.50.0 |
Resources
| Name | Type |
|---|---|
| aws_appautoscaling_policy.read | resource |
| aws_appautoscaling_policy.write | resource |
| aws_appautoscaling_target.read | resource |
| aws_appautoscaling_target.write | resource |
| aws_dynamodb_table.this | resource |
Inputs
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| tables | Map of DynamoDB table definitions | map(object({ name = string billing_mode = optional(string, "PAY_PER_REQUEST") read_capacity = optional(number, null) write_capacity = optional(number, null) hash_key = string range_key = optional(string, null) kms_key_arn = optional(string, null) point_in_time_recovery = optional(bool, true) ttl_attribute = optional(string, null) stream_enabled = optional(bool, false) stream_view_type = optional(string, "NEW_AND_OLD_IMAGES") table_class = optional(string, "STANDARD") attributes = list(object({ name = string type = string })) global_secondary_indexes = optional(list(object({ name = string hash_key = string range_key = optional(string, null) projection_type = optional(string, "ALL") non_key_attributes = optional(list(string), []) read_capacity = optional(number, null) write_capacity = optional(number, null) })), []) local_secondary_indexes = optional(list(object({ name = string range_key = string projection_type = optional(string, "ALL") non_key_attributes = optional(list(string), []) })), []) autoscaling = optional(object({ read_min_capacity = optional(number, 5) read_max_capacity = optional(number, 20) write_min_capacity = optional(number, 5) write_max_capacity = optional(number, 20) target_utilization = optional(number, 70) }), null) })) | {} |
no |
| tags | Resource tags to apply to all resources | map(string) |
{} |
no |
Outputs
| Name | Description |
|---|---|
| stream_arns | Map of table keys to DynamoDB stream ARNs (null for tables without streams) |
| stream_labels | Map of table keys to DynamoDB stream labels (null for tables without streams) |
| table_arns | Map of table keys to DynamoDB table ARNs |
| table_ids | Map of table keys to DynamoDB table IDs |
| table_names | Map of table keys to DynamoDB table names |