-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
130 lines (109 loc) · 3.65 KB
/
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Local Vars
locals {
ddb_endpoint = var.env == "local" ? var.local_ddb_endpoint : "https://dynamodb.${var.aws_region}.amazonaws.com"
ddb_default_write_cap = 5
ddb_default_read_cap = 5
}
provider "aws" {
version = "~> 2.0"
region = var.aws_region
# Skip the AWS validation steps
skip_credentials_validation = var.env == "local" ? true : false
skip_requesting_account_id = var.env == "local" ? true : false
endpoints {
dynamodb = local.ddb_endpoint # Point to endpoint depending on env
}
}
resource "aws_dynamodb_table" "target_store" {
name = "Store"
billing_mode = "PROVISIONED"
read_capacity = 5
write_capacity = 5
hash_key = "Address.Subdivision"
range_key = "ID"
attribute {
name = "Address.Subdivision"
type = "S"
}
attribute {
name = "ID"
type = "N"
}
attribute {
name = "IsDaylightSavingsTimeRecognized"
type = "S"
}
attribute {
name = "X.locale"
type = "S"
}
attribute {
name = "PhoneNumber"
type = "S"
}
# Custom - Fields that are not in original data set but are pre-computed for dynamodb
attribute {
name = "CityZip"
type = "S"
}
attribute {
name = "Starbucks"
type = "S"
}
attribute {
name = "CVS"
type = "S"
}
ttl {
attribute_name = "TimeToExist"
enabled = false
}
# Query by store ID - Given ID, return all attributes for store (ID: 1957)
global_secondary_index {
name = "Query-By-Store-State"
hash_key = "Address.Subdivision"
range_key = "ID"
write_capacity = local.ddb_default_write_cap
read_capacity = local.ddb_default_read_cap
projection_type = "ALL"
}
# Query by store that do not observe day light saving
global_secondary_index {
name = "Query-By-DayLightSavings"
hash_key = "IsDaylightSavingsTimeRecognized"
#range_key = "" # Omitted range key
write_capacity = local.ddb_default_write_cap
read_capacity = local.ddb_default_read_cap
projection_type = "KEYS_ONLY"
}
# Given a phone area code, return all stores with formatted addresses and phone numbers (Area Code: 206).
global_secondary_index {
name = "Query-By-Phone-Area-Code"
hash_key = "X.locale"
range_key = "PhoneNumber" # Omitted range key
write_capacity = local.ddb_default_write_cap
read_capacity = local.ddb_default_read_cap
projection_type = "ALL"
}
# Return all attributes for all stores with Starbucks and CVS.
global_secondary_index {
name = "Query-By-Starbucks-And-CSV"
hash_key = "Starbucks"
range_key = "CVS"
write_capacity = local.ddb_default_write_cap
read_capacity = local.ddb_default_read_cap
projection_type = "ALL"
}
# Query by State, City and Zip
# Query 1 : Given state and city, return all attributes for all stores (State: WA; City: Seattle).
# Query 2 : Given state city and zip, return all attributes for all stores (State: WA; City: Seattle; Zip: 98125).
local_secondary_index {
name = "Query-By-State-CityZip"
range_key = "CityZip"
projection_type = "ALL"
}
tags = {
Name = "dynamodb-table-store-${var.env}" # convention: dyanmodb-table-store-{env}
Environment = var.env
}
}