-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvariables.tf
342 lines (317 loc) · 10.6 KB
/
variables.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
##############################################################################
# Account Variables
##############################################################################
variable "region" {
description = "The region to which to deploy the VPC"
type = string
}
variable "prefix" {
description = "The prefix that you would like to append to your resources"
type = string
}
variable "tags" {
description = "List of Tags for the resource created"
type = list(string)
default = null
}
variable "use_random_suffix" {
description = "Add a randomize suffix to the end of each resource created in this module."
type = bool
default = true
}
variable "key_management_service_guid" {
description = "OPTIONAL - GUID of the Key Management Service to use for COS bucket encryption."
type = string
default = null
}
variable "key_management_service_name" {
description = "OPTIONAL - Type of key management service to use for COS bucket encryption. Service authorizations will be added only if the GUID is not null."
type = string
default = null
validation {
error_message = "Key Management service name can be `kms`, `hs-crypto`, or `null`."
condition = var.key_management_service_name == null || var.key_management_service_name == "kms" || var.key_management_service_name == "hs-crypto"
}
}
variable "service_endpoints" {
description = "Service endpoints. Can be `public`, `private`, or `public-and-private`"
type = string
default = "private"
validation {
error_message = "Service endpoints can only be `public`, `private`, or `public-and-private`."
condition = contains(["public", "private", "public-and-private"], var.service_endpoints)
}
}
variable "key_management_keys" {
description = "List of key management keys from key_management module"
type = list(
object({
shortname = string
name = string
id = string
crn = string
key_id = string
})
)
default = []
}
##############################################################################
##############################################################################
# Cloud Object Storage Variables
##############################################################################
variable "cos" {
description = "Object describing the cloud object storage instance, buckets, and keys. Set `use_data` to false to create instance"
type = list(
object({
name = string
use_data = optional(bool)
resource_group_id = optional(string)
plan = optional(string)
buckets = list(object({
name = string
storage_class = string
endpoint_type = string
force_delete = bool
single_site_location = optional(string)
region_location = optional(string)
cross_region_location = optional(string)
kms_key = optional(string)
allowed_ip = optional(list(string))
hard_quota = optional(number)
archive_rule = optional(object({
days = number
enable = bool
rule_id = optional(string)
type = string
}))
activity_tracking = optional(object({
activity_tracker_crn = string
read_data_events = bool
write_data_events = bool
}))
metrics_monitoring = optional(object({
metrics_monitoring_crn = string
request_metrics_enabled = optional(bool)
usage_metrics_enabled = optional(bool)
}))
}))
keys = optional(
list(object({
name = string
role = string
enable_HMAC = bool
}))
)
})
)
default = [
{
buckets = [
{
endpoint_type = "public"
force_delete = true
kms_key = "at-test-atracker-key"
name = "atracker-bucket"
storage_class = "standard"
},
]
keys = [
{
enable_HMAC = false
name = "cos-bind-key"
role = "Writer"
},
]
name = "atracker-cos"
plan = "standard"
random_suffix = true
resource_group = "at-test-service-rg"
use_data = false
},
{
buckets = [
{
endpoint_type = "public"
force_delete = true
kms_key = "at-test-slz-key"
name = "management-bucket"
storage_class = "standard"
},
{
endpoint_type = "public"
force_delete = true
kms_key = "at-test-slz-key"
name = "workload-bucket"
storage_class = "standard"
},
{
endpoint_type = "public"
force_delete = true
kms_key = "at-test-slz-key"
name = "bastion-bucket"
storage_class = "standard"
},
]
keys = [
{
enable_HMAC = true
name = "bastion-key"
role = "Writer"
},
]
name = "cos"
plan = "standard"
random_suffix = true
resource_group = "at-test-service-rg"
use_data = false
},
]
validation {
error_message = "Each COS key must have a unique name."
condition = length(var.cos) == 0 ? true : length(
flatten(
[
for instance in var.cos :
[
for keys in instance.keys :
keys.name
] if lookup(instance, "keys", false) != false
]
)
) == length(
distinct(
flatten(
[
for instance in var.cos :
[
for keys in instance.keys :
keys.name
] if lookup(instance, "keys", false) != false
]
)
)
)
}
validation {
error_message = "Plans for COS instances can only be `lite` or `standard`."
condition = length(var.cos) == 0 ? true : length([
for instance in var.cos :
true if contains(["lite", "standard"], instance.plan)
]) == length(var.cos)
}
validation {
error_message = "COS Bucket names must be unique."
condition = length(var.cos) == 0 ? true : length(
flatten([
for instance in var.cos :
instance.buckets.*.name
])
) == length(
distinct(
flatten([
for instance in var.cos :
instance.buckets.*.name
])
)
)
}
# https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-classes
validation {
error_message = "Storage class can only be `standard`, `vault`, `cold`, or `smart`."
condition = length(var.cos) == 0 ? true : length(
flatten(
[
for instance in var.cos :
[
for bucket in instance.buckets :
true if contains(["standard", "vault", "cold", "smart"], bucket.storage_class)
]
]
)
) == length(flatten([for instance in var.cos : [for bucket in instance.buckets : true]]))
}
# https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/cos_bucket#endpoint_type
validation {
error_message = "Endpoint type can only be `public`, `private`, or `direct`."
condition = length(var.cos) == 0 ? true : length(
flatten(
[
for instance in var.cos :
[
for bucket in instance.buckets :
true if contains(["public", "private", "direct"], bucket.endpoint_type)
]
]
)
) == length(flatten([for instance in var.cos : [for bucket in instance.buckets : true]]))
}
# https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/cos_bucket#single_site_location
validation {
error_message = "All single site buckets must specify `ams03`, `che01`, `hkg02`, `mel01`, `mex01`, `mil01`, `mon01`, `osl01`, `par01`, `sjc04`, `sao01`, `seo01`, `sng01`, or `tor01`."
condition = length(var.cos) == 0 ? true : length(
[
for site_bucket in flatten(
[
for instance in var.cos :
[
for bucket in instance.buckets :
bucket if lookup(bucket, "single_site_location", null) != null
]
]
) : site_bucket if !contains(["ams03", "che01", "hkg02", "mel01", "mex01", "mil01", "mon01", "osl01", "par01", "sjc04", "sao01", "seo01", "sng01", "tor01"], site_bucket.single_site_location)
]
) == 0
}
# https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/cos_bucket#region_location
validation {
error_message = "All regional buckets must specify `au-syd`, `eu-de`, `eu-gb`, `jp-tok`, `us-east`, `us-south`, `ca-tor`, `jp-osa`, `br-sao`."
condition = length(var.cos) == 0 ? true : length(
[
for site_bucket in flatten(
[
for instance in var.cos :
[
for bucket in instance.buckets :
bucket if lookup(bucket, "region_location", null) != null
]
]
) : site_bucket if !contains(["au-syd", "eu-de", "eu-gb", "jp-tok", "us-east", "us-south", "ca-tor", "jp-osa", "br-sao"], site_bucket.region_location)
]
) == 0
}
# https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/cos_bucket#cross_region_location
validation {
error_message = "All cross-regional buckets must specify `us`, `eu`, `ap`."
condition = length(var.cos) == 0 ? true : length(
[
for site_bucket in flatten(
[
for instance in var.cos :
[
for bucket in instance.buckets :
bucket if lookup(bucket, "cross_region_location", null) != null
]
]
) : site_bucket if !contains(["us", "eu", "ap"], site_bucket.cross_region_location)
]
) == 0
}
# https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/cos_bucket#archive_rule
validation {
error_message = "Each archive rule must specify a type of `Glacier` or `Accelerated`."
condition = length(var.cos) == 0 ? true : length(
[
for site_bucket in flatten(
[
for instance in var.cos :
[
for bucket in instance.buckets :
bucket if lookup(bucket, "archive_rule", null) != null
]
]
) : site_bucket if !contains(["Glacier", "Accelerated"], site_bucket.archive_rule.type)
]
) == 0
}
}
##############################################################################