-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdynamodb-tables-main.tf
88 lines (78 loc) · 2.09 KB
/
dynamodb-tables-main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Create DynamoDB Table
resource "aws_dynamodb_table" "book_catalog_table" {
name = "BookCatalog"
billing_mode = "PROVISIONED"
read_capacity = 1
write_capacity = 1
hash_key = "BookName"
attribute {
name = "BookName"
type = "S"
}
attribute {
name = "Author"
type = "S"
}
global_secondary_index {
name = "Author-Index"
hash_key = "Author"
write_capacity = 1
read_capacity = 1
projection_type = "INCLUDE"
non_key_attributes = ["Genre"]
}
tags = {
Name = "book-catalog-table"
Environment = "production"
}
}
// Create DynamoDB Single Item
resource "aws_dynamodb_table_item" "book_catalog_item_1" {
table_name = aws_dynamodb_table.book_catalog_table.name
hash_key = aws_dynamodb_table.book_catalog_table.hash_key
item = <<ITEM
{
"BookName": {"S": "Seven Fires"},
"Author": {"S": "Francis Mallmann"},
"Genre": {"S": "Cooking"}
}
ITEM
}
// Create DynamoDB Single Item
resource "aws_dynamodb_table_item" "book_catalog_item_2" {
table_name = aws_dynamodb_table.book_catalog_table.name
hash_key = aws_dynamodb_table.book_catalog_table.hash_key
item = <<ITEM
{
"BookName": {"S": "The Most Beautiful Walk in the World"},
"Author": {"S": "John Baxter"},
"Genre": {"S": "Travel"}
}
ITEM
}
// Create DynamoDB Multiple Items
resource "aws_dynamodb_table_item" "book_catalog_fiction_items" {
table_name = aws_dynamodb_table.book_catalog_table.name
hash_key = aws_dynamodb_table.book_catalog_table.hash_key
for_each = {
"Rayuela" = {
author = "Julio Cortazar"
genre = "Fiction"
}
"A Moveable Feast" = {
author = "Ernest Hemingway"
genre = "Fiction"
}
"The Great Gatsby" = {
author = "F. Scott Fitzgerald"
genre = "Fiction"
}
}
item = <<ITEM
{
"BookName": {"S": "${each.key}"},
"Author": {"S": "${each.value.author}"},
"Genre": {"S": "${each.value.genre}"}
}
ITEM
}