Skip to content

Commit d8bc264

Browse files
committed
Add configurable SSL settings for Cloud SQL database
- Add database_require_ssl variable with default true - Add database_ssl_mode variable with default ENCRYPTED_ONLY - Include validation for ssl_mode to ensure valid GCP values - Apply SSL configuration to Cloud SQL ip_configuration block
1 parent bb5f29d commit d8bc264

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ No modules.
226226
| <a name="input_database_disk_autoresize_limit"></a> [database\_disk\_autoresize\_limit](#input\_database\_disk\_autoresize\_limit) | Maximum disk size in GB for database autoresize | `number` | `100` | no |
227227
| <a name="input_database_disk_size"></a> [database\_disk\_size](#input\_database\_disk\_size) | Database disk size in GB | `number` | `20` | no |
228228
| <a name="input_database_log_retention_days"></a> [database\_log\_retention\_days](#input\_database\_log\_retention\_days) | Number of days to retain database transaction logs | `number` | `7` | no |
229+
| <a name="input_database_require_ssl"></a> [database\_require\_ssl](#input\_database\_require\_ssl) | Require SSL for database connections | `bool` | `true` | no |
230+
| <a name="input_database_ssl_mode"></a> [database\_ssl\_mode](#input\_database\_ssl\_mode) | SSL mode for database connections | `string` | `"ENCRYPTED_ONLY"` | no |
229231
| <a name="input_database_tier"></a> [database\_tier](#input\_database\_tier) | Database instance tier | `string` | `"db-f1-micro"` | no |
230232
| <a name="input_enable_cloudflare_dns"></a> [enable\_cloudflare\_dns](#input\_enable\_cloudflare\_dns) | Enable Cloudflare DNS management | `bool` | `false` | no |
231233
| <a name="input_enable_database"></a> [enable\_database](#input\_enable\_database) | Enable Cloud SQL database deployment | `bool` | `true` | no |

database.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ resource "google_sql_database_instance" "main" {
4343
ipv4_enabled = false
4444
private_network = google_compute_network.main.id
4545
enable_private_path_for_google_cloud_services = true
46-
require_ssl = true
46+
require_ssl = var.database_require_ssl
47+
ssl_mode = var.database_ssl_mode
4748
}
4849

4950
# Database flags for optimal performance

variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ variable "database_log_retention_days" {
8181
default = 7
8282
}
8383

84+
variable "database_require_ssl" {
85+
description = "Require SSL for database connections"
86+
type = bool
87+
default = true
88+
}
89+
90+
variable "database_ssl_mode" {
91+
description = "SSL mode for database connections"
92+
type = string
93+
default = "ENCRYPTED_ONLY"
94+
validation {
95+
condition = contains(["ALLOW_UNENCRYPTED_AND_ENCRYPTED", "ENCRYPTED_ONLY", "TRUSTED_CLIENT_CERTIFICATE_REQUIRED"], var.database_ssl_mode)
96+
error_message = "SSL mode must be one of: ALLOW_UNENCRYPTED_AND_ENCRYPTED, ENCRYPTED_ONLY, TRUSTED_CLIENT_CERTIFICATE_REQUIRED."
97+
}
98+
}
99+
84100
# Application Configuration
85101
variable "app_image" {
86102
description = "Container image for the hrafnar application (without tag)"

0 commit comments

Comments
 (0)