-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.tf
91 lines (79 loc) · 2.17 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
#############################
# DynamoDB
#############################
resource "aws_dynamodb_table" "main-table" {
name = var.table-name
billing_mode = "PROVISIONED"
read_capacity = 2
write_capacity = 2
hash_key = "orderId"
range_key = "customerId"
attribute {
name = "orderId"
type = "S"
}
attribute {
name = "customerId"
type = "S"
}
attribute {
name = "shipped"
type = "S"
}
local_secondary_index {
name = "lsi-orderId-customerId"
range_key = "customerId"
projection_type = "ALL"
}
global_secondary_index {
name = "gsi-shipped"
hash_key = "orderId"
range_key = "shipped"
write_capacity = 1
read_capacity = 1
projection_type = "ALL"
}
tags = {
Name = "${var.table-name}-${var.environment}"
Environment = var.environment
}
}
#
# REMBER ONLY UNCOMMENT ONE OF THE TWO STEPS BELOW. THE Go script requires compiling, instructions provided in the README
#
###################################
# Execut AWS CLI script Option 1/2
###################################
# resource "null_resource" "init-db" {
// This will cause the upload script to only execute when the table changes id (recreate).
# triggers = {
# new = aws_dynamodb_table.main-table.id
# }
# provisioner "local-exec" {
# command = <<EOT
# aws dynamodb batch-write-item --request-items file://static/formatted-data.json --endpoint-url ${var.dynamodb-addr}
# EOT
# }
# depends_on = [aws_dynamodb_table.main-table]
# }
#####################################
# Execut Go binary script Option 2/2
#####################################
resource "null_resource" "init-db-go" {
// This will cause the upload script to only execute when the table changes id (recreate).
triggers = {
new = aws_dynamodb_table.main-table.id
}
provisioner "local-exec" {
command = <<EOT
./upload-logic
EOT
environment = {
TABLE_NAME = aws_dynamodb_table.main-table.id
REGION = var.region
DYNAMODB_ADDR = var.dynamodb-addr
JSON_PATH = var.json-file-path
}
}
depends_on = [aws_dynamodb_table.main-table]
}