Skip to content

Commit ba22c3f

Browse files
author
kfc-manager
committed
enha: added option to define table stream
1 parent 53ed39d commit ba22c3f

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

main.tf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ locals {
1010
}
1111

1212
resource "aws_dynamodb_table" "main" {
13-
billing_mode = var.provisioned != null ? "PROVISIONED" : "PAY_PER_REQUEST"
14-
hash_key = var.hash_key["name"]
15-
range_key = try(var.sort_key["name"], null)
16-
name = var.identifier
17-
read_capacity = try(var.provisioned["read_capacity"], null)
18-
write_capacity = try(var.provisioned["write_capacity"], null)
13+
billing_mode = var.provisioned != null ? "PROVISIONED" : "PAY_PER_REQUEST"
14+
hash_key = var.hash_key["name"]
15+
range_key = try(var.sort_key["name"], null)
16+
name = var.identifier
17+
read_capacity = try(var.provisioned["read_capacity"], null)
18+
write_capacity = try(var.provisioned["write_capacity"], null)
19+
stream_enabled = var.stream_view != null
20+
stream_view_type = var.stream_view
1921

2022
dynamic "attribute" {
2123
for_each = local.attributes

outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ output "arn" {
77
description = "ARN of the DynamoDB table."
88
value = try(aws_dynamodb_table.main.arn, null)
99
}
10+
11+
output "stream_arn" {
12+
description = "ARN of the stream of the DynamoDB table."
13+
value = try(aws_dynamodb_table.main.stream_arn, null)
14+
}

tests/table.tftest.hcl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,30 @@ run "valid_identifier" {
3333
}
3434
}
3535

36+
run "invalid_stream_view" {
37+
command = plan
38+
39+
variables {
40+
identifier = "abc"
41+
hash_key = {
42+
name = "TestPKey"
43+
type = "S"
44+
}
45+
stream_view = "TEST_ONLY"
46+
}
47+
48+
expect_failures = [var.stream_view]
49+
}
3650

51+
run "valid_stream_view" {
52+
command = plan
53+
54+
variables {
55+
identifier = "abc"
56+
hash_key = {
57+
name = "TestPKey"
58+
type = "S"
59+
}
60+
stream_view = "KEYS_ONLY"
61+
}
62+
}

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ variable "gsi_keys" {
5353
default = []
5454
}
5555

56+
variable "stream_view" {
57+
description = "View type of streams from the DynamoDB table. Valid values are: 'KEYS_ONLY', 'NEW_IMAGE', 'OLD_IMAGE', 'NEW_AND_OLD_IMAGES' and null. If null streams will be disabled."
58+
type = string
59+
default = null
60+
validation {
61+
condition = var.stream_view == null || var.stream_view == "KEYS_ONLY" || (
62+
var.stream_view == "NEW_IMAGE") || var.stream_view == "OLD_IMAGE" || (
63+
var.stream_view == "NEW_AND_OLD_IMAGES")
64+
error_message = "Stream view must be 'KEYS_ONLY', 'NEW_IMAGE', 'OLD_IMAGE', 'NEW_AND_OLD_IMAGES' or null"
65+
}
66+
}
67+
5668
variable "tags" {
5769
description = "A map of tags to add to all resources."
5870
type = map(string)

0 commit comments

Comments
 (0)