-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.tf
188 lines (156 loc) · 4.16 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
provider "aws" {
region = "us-east-1"
}
data "aws_caller_identity" "this" {}
data "aws_partition" "this" {}
data "aws_region" "this" {}
locals {
partition = data.aws_partition.this.partition
region = data.aws_region.this.name
account_id = data.aws_caller_identity.this.account_id
}
data "aws_iam_policy_document" "this" {
statement {
actions = [
"glue:*",
]
resources = [
"arn:${local.partition}:glue:${local.region}:${local.account_id}:catalog",
"arn:${local.partition}:glue:${local.region}:${local.account_id}:database/*",
"arn:${local.partition}:glue:${local.region}:${local.account_id}:table/*/*"
]
principals {
identifiers = ["*"]
type = "AWS"
}
}
statement {
actions = [
"glue:ShareResource"
]
resources = [
"arn:${local.partition}:glue:${local.region}:${local.account_id}:catalog",
"arn:${local.partition}:glue:${local.region}:${local.account_id}:database/*",
"arn:${local.partition}:glue:${local.region}:${local.account_id}:table/*/*"
]
principals {
identifiers = ["ram.amazonaws.com"]
type = "Service"
}
}
}
locals {
databases = [
{
name = "foo"
description = "Hello, foo"
tables = [
{
name = "foo1"
descrition = "Hey, foo1"
},
{
name = "foo2"
descrition = "Hey, foo2"
},
]
},
{
name = "bar"
description = "Hello, bar"
tables = [
{
name = "bar1"
descrition = "Hey, bar1"
},
{
name = "bar2"
descrition = "Hey, bar2"
},
]
}
]
tables = flatten([
for database in try(local.databases, []) : [
for table in try(database.tables, []) :
merge(table, {
database = database.name
})
]
])
}
###################################################
# KMS Keys for Glue
###################################################
module "kms_key" {
source = "tedilabs/secret/aws//modules/kms-key"
version = "~> 0.3.0"
name = "example-glue"
aliases = ["alias/example-glue"]
description = "Managed by Terraform."
usage = "ENCRYPT_DECRYPT"
spec = "SYMMETRIC_DEFAULT"
policy = null
deletion_window_in_days = 7
tags = {
"project" = "terraform-aws-data-examples"
}
}
###################################################
# Glue Data Catalog
###################################################
module "data_catalog" {
source = "../../modules/glue-data-catalog"
# source = "tedilabs/data/aws//modules/glue-data-catalog"
# version = "~> 0.2.0"
policy = data.aws_iam_policy_document.this.json
encryption_for_connection_passwords = {
enabled = true
kms_key = module.kms_key.arn
}
encryption_at_rest = {
enabled = true
kms_key = module.kms_key.arn
}
tags = {
"project" = "terraform-aws-data-examples"
}
}
###################################################
# Glue Database
###################################################
module "database" {
source = "../../modules/glue-database"
# source = "tedilabs/data/aws//modules/glue-database"
# version = "~> 0.2.0"
for_each = {
for database in try(local.databases, []) :
database.name => database
}
catalog = try(each.value.catalog, null)
name = each.key
description = try(each.value.description, "Managed by Terraform.")
location_uri = try(each.value.location_uri, "")
tags = {
"project" = "terraform-aws-data-examples"
}
}
###################################################
# Glue Table
###################################################
module "table" {
source = "../../modules/glue-table"
# source = "tedilabs/data/aws//modules/glue-table"
# version = "~> 0.2.0"
for_each = {
for table in try(local.tables, []) :
"${table.database}/${table.name}" => table
}
catalog = try(each.value.catalog, null)
database = module.database[each.value.database].name
name = each.value.name
description = try(each.value.description, "Managed by Terraform.")
tags = {
"project" = "terraform-aws-data-examples"
}
}