-
Notifications
You must be signed in to change notification settings - Fork 1
/
dynamodb.tf
47 lines (40 loc) · 1.15 KB
/
dynamodb.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
resource "aws_dynamodb_table" "dynamodbtable" {
name = "counter"
billing_mode = "PROVISIONED"
read_capacity = 1
write_capacity = 1
hash_key = "id"
attribute {
name = "id"
type = "N"
}
# ttl {
# attribute_name = "TimeToExist"
# enabled = false
# }
# TTL does not update quickly at AWS side, and you get a validation
# error if you create the table with TTL specified like above, and
# need to run another TF apply/plan etc.
global_secondary_index {
name = "idIndex"
hash_key = "id"
write_capacity = 1
read_capacity = 1
projection_type = "KEYS_ONLY"
}
}
resource "aws_dynamodb_table_item" "tableitem" {
table_name = aws_dynamodb_table.dynamodbtable.name
hash_key = aws_dynamodb_table.dynamodbtable.hash_key
item = <<ITEM
{
"id": {"N": "0"}
}
ITEM
}
# "visitcount": {"N": "0"}
# Had to remove the visitcount field
# it was used to create the table initially, but,
# when run subsequently it would overwrite the counter value
# even though it would not destroy the table and recreate.
# Removed this as a temp workaround for now