Skip to content

Commit 4170748

Browse files
authored
Merge pull request #67 from MaterializeInc/fix/add-vpc-wait-before-db-creation
Add 60s wait for VPC readiness before Cloud SQL instance creation
2 parents 4c2273e + 830d396 commit 4170748

6 files changed

Lines changed: 35 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ No resources.
7979
| <a name="input_cert_manager_install_timeout"></a> [cert\_manager\_install\_timeout](#input\_cert\_manager\_install\_timeout) | Timeout for installing the cert-manager helm chart, in seconds. | `number` | `300` | no |
8080
| <a name="input_cert_manager_namespace"></a> [cert\_manager\_namespace](#input\_cert\_manager\_namespace) | The name of the namespace in which cert-manager is or will be installed. | `string` | `"cert-manager"` | no |
8181
| <a name="input_database_config"></a> [database\_config](#input\_database\_config) | Cloud SQL configuration | <pre>object({<br/> tier = optional(string, "db-custom-2-4096")<br/> version = optional(string, "POSTGRES_15")<br/> password = string<br/> username = optional(string, "materialize")<br/> db_name = optional(string, "materialize")<br/> })</pre> | n/a | yes |
82+
| <a name="input_database_vpc_wait_duration"></a> [database\_vpc\_wait\_duration](#input\_database\_vpc\_wait\_duration) | Duration to wait for VPC resources to be ready before creating the database (e.g., '60s', '2m') | `string` | `"60s"` | no |
8283
| <a name="input_helm_chart"></a> [helm\_chart](#input\_helm\_chart) | Chart name from repository or local path to chart. For local charts, set the path to the chart directory. | `string` | `"materialize-operator"` | no |
8384
| <a name="input_helm_values"></a> [helm\_values](#input\_helm\_values) | Values to pass to the Helm chart | `any` | `{}` | no |
8485
| <a name="input_install_cert_manager"></a> [install\_cert\_manager](#input\_install\_cert\_manager) | Whether to install cert-manager. | `bool` | `true` | no |

main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ module "database" {
8181
db_version = var.database_config.version
8282
password = var.database_config.password
8383

84+
private_vpc_connection = module.networking.private_vpc_connection
85+
vpc_wait_duration = var.database_vpc_wait_duration
86+
8487
labels = local.common_labels
8588
}
8689

modules/database/main.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
resource "time_sleep" "wait_for_vpc" {
2+
depends_on = [var.private_vpc_connection]
3+
4+
create_duration = var.vpc_wait_duration
5+
}
6+
17
resource "google_sql_database_instance" "materialize" {
8+
depends_on = [time_sleep.wait_for_vpc]
9+
210
name = "${var.prefix}-pg"
311
database_version = var.db_version
412
region = var.region
513
project = var.project_id
614

715
timeouts {
8-
create = "60m"
16+
create = "75m"
917
update = "45m"
1018
delete = "45m"
1119
}

modules/database/providers.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ terraform {
66
source = "hashicorp/google"
77
version = ">= 6.0"
88
}
9+
time = {
10+
source = "hashicorp/time"
11+
version = "~> 0.13"
12+
}
913
}
1014
}

modules/database/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ variable "network_id" {
1818
type = string
1919
}
2020

21+
variable "private_vpc_connection" {
22+
description = "The private VPC connection dependency"
23+
type = any
24+
default = null
25+
}
26+
2127
variable "tier" {
2228
description = "The machine tier for the database instance"
2329
type = string
@@ -55,3 +61,9 @@ variable "labels" {
5561
type = map(string)
5662
default = {}
5763
}
64+
65+
variable "vpc_wait_duration" {
66+
description = "Duration to wait for VPC resources to be ready (e.g., '60s')"
67+
type = string
68+
default = "60s"
69+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ variable "database_config" {
100100
}
101101
}
102102

103+
variable "database_vpc_wait_duration" {
104+
description = "Duration to wait for VPC resources to be ready before creating the database (e.g., '60s', '2m')"
105+
type = string
106+
default = "60s"
107+
}
108+
103109
variable "namespace" {
104110
description = "Kubernetes namespace for Materialize"
105111
type = string

0 commit comments

Comments
 (0)