-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariables.tf
More file actions
451 lines (392 loc) · 11.9 KB
/
variables.tf
File metadata and controls
451 lines (392 loc) · 11.9 KB
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# Core GCP Configuration
variable "project_id" {
description = "The GCP project ID where resources will be created"
type = string
}
variable "region" {
description = "The GCP region for resources"
type = string
default = "us-central1"
}
variable "name_prefix" {
description = "Prefix for resource naming"
type = string
validation {
condition = can(regex("^[a-z0-9-]+$", var.name_prefix))
error_message = "Name prefix must contain only lowercase letters, numbers, and hyphens."
}
}
# Networking Configuration
variable "vpc_cidr" {
description = "CIDR block for the VPC"
type = string
default = "10.0.0.0/16"
}
variable "private_subnet_cidr" {
description = "CIDR block for the private subnet"
type = string
default = "10.0.0.0/24"
validation {
condition = can(regex("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/[0-9]{1,2}$", var.private_subnet_cidr))
error_message = "Invalid CIDR format."
}
# Ensure CIDR is /26 or larger (See https://cloud.google.com/run/docs/configuring/vpc-direct-vpc#scale_down for more info)
validation {
condition = can(regex("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/[0-9]{1,2}$", var.private_subnet_cidr)) && (tonumber(regex("[0-9]{1,2}$", var.private_subnet_cidr)) <= 26)
error_message = "CIDR range must be /26 or larger (required by direct VPC egress)."
}
}
variable "enable_nat_gateway" {
description = "Enable Cloud NAT for outbound internet access"
type = bool
default = true
}
# Database Configuration
variable "enable_database" {
description = "Enable Cloud SQL database deployment"
type = bool
default = true
}
variable "database_tier" {
description = "Database instance tier"
type = string
default = "db-f1-micro"
}
variable "database_disk_size" {
description = "Database disk size in GB"
type = number
default = 20
}
variable "database_backup_enabled" {
description = "Enable automated database backups"
type = bool
default = true
}
variable "database_disk_autoresize_limit" {
description = "Maximum disk size in GB for database autoresize"
type = number
default = 100
}
variable "database_backup_retention_days" {
description = "Number of days to retain database backups"
type = number
default = 7
}
variable "database_log_retention_days" {
description = "Number of days to retain database transaction logs"
type = number
default = 7
}
variable "database_ssl_mode" {
description = "SSL mode for database connections"
type = string
default = "ENCRYPTED_ONLY"
validation {
condition = contains(["ALLOW_UNENCRYPTED_AND_ENCRYPTED", "ENCRYPTED_ONLY", "TRUSTED_CLIENT_CERTIFICATE_REQUIRED"], var.database_ssl_mode)
error_message = "SSL mode must be one of: ALLOW_UNENCRYPTED_AND_ENCRYPTED, ENCRYPTED_ONLY, TRUSTED_CLIENT_CERTIFICATE_REQUIRED."
}
}
# Valkey/Redis Configuration
variable "enable_valkey" {
description = "Enable Google Cloud Memorystore for Redis (Valkey-compatible) deployment"
type = bool
default = false
}
variable "valkey_memory_size_gb" {
description = "Redis instance memory size in GB"
type = number
default = 1
}
variable "valkey_tier" {
description = "Service tier of the Redis instance (BASIC or STANDARD_HA)"
type = string
default = "BASIC"
validation {
condition = contains(["BASIC", "STANDARD_HA"], var.valkey_tier)
error_message = "Valkey tier must be either BASIC or STANDARD_HA."
}
}
variable "valkey_redis_version" {
description = "Redis version for the instance"
type = string
default = "REDIS_7_0"
validation {
condition = contains(["REDIS_6_X", "REDIS_7_0"], var.valkey_redis_version)
error_message = "Redis version must be either REDIS_6_X or REDIS_7_0."
}
}
variable "valkey_auth_enabled" {
description = "Whether AUTH is enabled for the Redis instance"
type = bool
default = true
}
variable "valkey_transit_encryption_mode" {
description = "TLS mode for Redis instance"
type = string
default = "SERVER_AUTHENTICATION"
validation {
condition = contains(["DISABLED", "SERVER_AUTHENTICATION"], var.valkey_transit_encryption_mode)
error_message = "Transit encryption mode must be either DISABLED or SERVER_AUTH."
}
}
variable "valkey_redis_configs" {
description = "Redis configuration parameters"
type = map(string)
default = {
maxmemory-policy = "allkeys-lru"
}
}
variable "valkey_maintenance_policy" {
description = "Maintenance policy for Redis instance"
type = object({
weekly_maintenance_window = object({
day = string # MONDAY, TUESDAY, etc.
start_time = object({
hours = number # 0-23
minutes = number # 0-59
seconds = number # 0-59
nanos = number # 0-999999999
})
})
})
default = {
weekly_maintenance_window = {
day = "SUNDAY"
start_time = {
hours = 3
minutes = 0
seconds = 0
nanos = 0
}
}
}
}
# Application Configuration
variable "app_image" {
description = "Container image for the hrafnar application (without tag)"
type = string
}
variable "app_image_tag" {
description = "Container image tag"
type = string
default = "latest"
}
variable "app_image_sha" {
description = "Container image SHA (takes precedence over tag if provided)"
type = string
default = ""
}
variable "app_port" {
description = "Port the application listens on"
type = number
default = 8080
}
variable "app_command" {
description = "Command to run the container"
type = list(string)
default = ["hrafnar", "serve"]
}
variable "app_cpu" {
description = "CPU allocation for the hrafnar application"
type = string
default = "1000m"
}
variable "app_memory" {
description = "Memory allocation for the hrafnar application"
type = string
default = "512Mi"
}
variable "app_min_instances" {
description = "Minimum number of instances for the hrafnar application"
type = number
default = 0
}
variable "app_max_instances" {
description = "Maximum number of instances for the hrafnar application"
type = number
default = 10
}
variable "app_env_vars" {
description = "Environment variables for the hrafnar application"
type = map(string)
default = {}
}
variable "app_config_files" {
description = "Configuration files to mount as volumes from Secret Manager. Key is the config name, value contains file content and mount path."
type = map(object({
content = string # File content to store in Secret Manager
mount_path = string # Path where file will be mounted in container (e.g., "/etc/config/app.yaml")
}))
default = {}
}
# AI Backend Configuration
variable "ai_api_keys" {
description = "Map of AI API keys where key is the environment variable name (e.g., OPENAI_API_KEY, ANTHROPIC_API_KEY) and value is the actual API key (stored in Secret Manager)"
type = map(string)
default = {}
sensitive = true
}
variable "mcp_servers" {
description = "MCP server configurations"
type = map(object({
url = string
api_key = optional(string)
description = string
}))
default = {}
}
# Storage Configuration
variable "enable_storage" {
description = "Enable Cloud Storage bucket for the application"
type = bool
default = false
}
variable "storage_force_destroy" {
description = "Force destroy the storage bucket even if it contains objects"
type = bool
default = false
}
variable "storage_versioning_enabled" {
description = "Enable versioning for the storage bucket"
type = bool
default = true
}
variable "storage_folders" {
description = "List of folders to create in the storage bucket"
type = list(string)
default = ["files", "thumbnails"]
}
variable "storage_public_access_prevention" {
description = "Public access prevention setting for the storage bucket"
type = string
default = "enforced"
validation {
condition = contains(["inherited", "enforced"], var.storage_public_access_prevention)
error_message = "Public access prevention must be either 'inherited' or 'enforced'."
}
}
variable "storage_app_role" {
description = "IAM role for the application to access the storage bucket"
type = string
default = "roles/storage.objectAdmin"
}
variable "storage_enable_dev_access" {
description = "Enable external access to the storage bucket for development"
type = bool
default = false
}
variable "storage_dev_role" {
description = "IAM role for development access to the storage bucket"
type = string
default = "roles/storage.objectAdmin"
}
variable "storage_dev_access_members" {
description = "List of IAM members to grant development access to the storage bucket (e.g., 'user:dev@example.com')"
type = list(string)
default = []
}
variable "storage_create_hmac_key" {
description = "Create HMAC key for S3-compatible access to the storage bucket"
type = bool
default = false
}
variable "storage_lifecycle_rules" {
description = "Lifecycle rules for the storage bucket"
type = list(object({
condition = object({
age = optional(number)
num_newer_versions = optional(number)
matches_prefix = optional(list(string))
matches_storage_class = optional(list(string))
})
action = object({
type = string
storage_class = optional(string)
})
}))
default = [
{
condition = {
age = 30
matches_prefix = ["thumbnails/"]
}
action = {
type = "Delete"
}
},
{
condition = {
num_newer_versions = 5
}
action = {
type = "Delete"
}
}
]
}
variable "storage_cors_config" {
description = "CORS configuration for the storage bucket"
type = list(object({
origin = list(string)
method = list(string)
response_header = list(string)
max_age_seconds = number
}))
default = [
{
origin = ["*"]
method = ["GET", "HEAD", "PUT", "POST", "DELETE"]
response_header = ["*"]
max_age_seconds = 3600
}
]
}
# DNS and TLS Configuration (Optional)
variable "enable_cloudflare_dns" {
description = "Enable Cloudflare DNS management"
type = bool
default = false
}
variable "cloudflare_zone_id" {
description = "Cloudflare zone ID for DNS records (required if enable_cloudflare_dns is true)"
type = string
default = ""
}
variable "base_domain" {
description = "Base domain name managed by Cloudflare (e.g., 'example.com'). A subdomain will be created under this domain for application access"
type = string
default = ""
}
variable "hrafnar_subdomain" {
description = "Subdomain for hrafnar application access (e.g., 'hrafnar' for hrafnar.example.com)"
type = string
default = "hrafnar"
}
# Artifact Registry Configuration
variable "enable_artifact_registry" {
description = "Enable Artifact Registry remote repository for quay.io"
type = bool
default = false
}
# Monitoring and Logging
variable "enable_monitoring" {
description = "Enable Google Cloud Monitoring and Logging"
type = bool
default = true
}
variable "log_level" {
description = "Log level for applications"
type = string
default = "INFO"
validation {
condition = contains(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], var.log_level)
error_message = "Log level must be one of: DEBUG, INFO, WARNING, ERROR, CRITICAL."
}
}
# Security Configuration
# Resource Tags
variable "labels" {
description = "Labels to apply to all resources"
type = map(string)
default = {}
}