From 5d4a0e19e9d7121349bf9237bda7798e1d493b16 Mon Sep 17 00:00:00 2001 From: rogerthatdev Date: Fri, 28 Jul 2023 13:00:05 -0700 Subject: [PATCH 01/11] reduce load balancer warmup --- infra/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/main.tf b/infra/main.tf index d509979d3..dc5c64199 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -295,7 +295,7 @@ resource "time_sleep" "load_balancer_warm_up_time" { google_compute_global_forwarding_rule.http ] - create_duration = "370s" + create_duration = "120s" } ### Firestore ### From db0281d2cdfe8ef8bbe1cf87b1ef24528e5f5af6 Mon Sep 17 00:00:00 2001 From: rogerthatdev Date: Fri, 28 Jul 2023 14:11:05 -0700 Subject: [PATCH 02/11] adjust with 30 sec padding --- infra/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/main.tf b/infra/main.tf index dc5c64199..0bac75cb1 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -295,7 +295,7 @@ resource "time_sleep" "load_balancer_warm_up_time" { google_compute_global_forwarding_rule.http ] - create_duration = "120s" + create_duration = "150s" } ### Firestore ### From 9ae06e2ee90c30ec0c4aa035965a2b520911e0ad Mon Sep 17 00:00:00 2001 From: rogerthatdev Date: Fri, 28 Jul 2023 14:11:45 -0700 Subject: [PATCH 03/11] global address wait for services --- infra/main.tf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/infra/main.tf b/infra/main.tf index 0bac75cb1..f4a50670d 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -217,6 +217,9 @@ resource "google_compute_region_network_endpoint_group" "default" { resource "google_compute_global_address" "default" { project = var.project_id name = "${var.deployment_name}-reserved-ip" + depends_on = [ + time_sleep.project_services + ] } resource "google_compute_url_map" "default" { From 7dbc872907625a52f818dd120a70466c678e22c3 Mon Sep 17 00:00:00 2001 From: rogerthatdev Date: Fri, 28 Jul 2023 14:16:40 -0700 Subject: [PATCH 04/11] tf fmt --- infra/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infra/main.tf b/infra/main.tf index f4a50670d..7da3fee73 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -217,9 +217,9 @@ resource "google_compute_region_network_endpoint_group" "default" { resource "google_compute_global_address" "default" { project = var.project_id name = "${var.deployment_name}-reserved-ip" - depends_on = [ + depends_on = [ time_sleep.project_services - ] + ] } resource "google_compute_url_map" "default" { From fea66d0b93aa6035b41c29fcb51d021bd57c2b4a Mon Sep 17 00:00:00 2001 From: rogerthatdev Date: Fri, 28 Jul 2023 15:53:32 -0700 Subject: [PATCH 05/11] replace time_sleep with http data source --- infra/main.tf | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/infra/main.tf b/infra/main.tf index 7da3fee73..1e2c24bb1 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -293,12 +293,22 @@ resource "google_compute_global_forwarding_rule" "http" { labels = var.labels } -resource "time_sleep" "load_balancer_warm_up_time" { +# It may take more than 2 minutes for the newly provisioned load balancer +# to forward requests to the Cloud Run service. The following data source +# allows for terraform apply to finish running when the end-point resolves + +data "http" "load_balancer_warm_up" { + url = "http://${google_compute_global_address.default.address}/" + # Attempt retry every 30 seconds 11 times, totalling to a 6 minute timeout. + retry { + attempts = 11 + max_delay_ms = 30000 + min_delay_ms = 30000 + } + # Begin trying after forwarding rule is created. depends_on = [ google_compute_global_forwarding_rule.http ] - - create_duration = "150s" } ### Firestore ### From 2023883a6c03bb9217cd87d274c92e7f4f6984b1 Mon Sep 17 00:00:00 2001 From: rogerthatdev Date: Fri, 28 Jul 2023 15:59:04 -0700 Subject: [PATCH 06/11] tighten retry to 20 secs --- infra/main.tf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/infra/main.tf b/infra/main.tf index 1e2c24bb1..001339aa8 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -299,11 +299,11 @@ resource "google_compute_global_forwarding_rule" "http" { data "http" "load_balancer_warm_up" { url = "http://${google_compute_global_address.default.address}/" - # Attempt retry every 30 seconds 11 times, totalling to a 6 minute timeout. + # Attempt retry every 20 seconds 17 times, totalling to a 6 minute timeout. retry { - attempts = 11 - max_delay_ms = 30000 - min_delay_ms = 30000 + attempts = 17 + max_delay_ms = 20000 + min_delay_ms = 20000 } # Begin trying after forwarding rule is created. depends_on = [ From 839eb88e8b0bee7cbfb9c455d86fe4f73644aaca Mon Sep 17 00:00:00 2001 From: rogerthatdev Date: Fri, 28 Jul 2023 16:03:13 -0700 Subject: [PATCH 07/11] typo --- infra/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/main.tf b/infra/main.tf index 001339aa8..944bc11b7 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -299,7 +299,7 @@ resource "google_compute_global_forwarding_rule" "http" { data "http" "load_balancer_warm_up" { url = "http://${google_compute_global_address.default.address}/" - # Attempt retry every 20 seconds 17 times, totalling to a 6 minute timeout. + # Attempt retry every 20 seconds 17 times, totaling to a 6 minute timeout. retry { attempts = 17 max_delay_ms = 20000 From b73b98b201514b5bb867e51c4d1ed03c5014a233 Mon Sep 17 00:00:00 2001 From: rogerthatdev Date: Fri, 28 Jul 2023 16:09:24 -0700 Subject: [PATCH 08/11] lint wants us to use the data source --- infra/outputs.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/outputs.tf b/infra/outputs.tf index 4c27eb07f..ef08b8a41 100644 --- a/infra/outputs.tf +++ b/infra/outputs.tf @@ -16,7 +16,7 @@ output "frontend_url" { description = "IP address to site. Load balancer expected to take ~5 minutes for it to warm up." - value = "http://${google_compute_global_address.default.address}/" + value = "${data.http.load_balancer_warm_up.url}" } output "neos_toc_url" { From f412d9fda71d06ab4f5c9bef69eb26fa5365fc03 Mon Sep 17 00:00:00 2001 From: rogerthatdev Date: Fri, 28 Jul 2023 16:14:01 -0700 Subject: [PATCH 09/11] tf fmt --- infra/outputs.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/outputs.tf b/infra/outputs.tf index ef08b8a41..c94097be7 100644 --- a/infra/outputs.tf +++ b/infra/outputs.tf @@ -16,7 +16,7 @@ output "frontend_url" { description = "IP address to site. Load balancer expected to take ~5 minutes for it to warm up." - value = "${data.http.load_balancer_warm_up.url}" + value = data.http.load_balancer_warm_up.url } output "neos_toc_url" { From 98e0e35b8f864bb1b023a6973f98487a68017f5f Mon Sep 17 00:00:00 2001 From: rogerthatdev Date: Fri, 28 Jul 2023 16:24:29 -0700 Subject: [PATCH 10/11] lint again ugh --- infra/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/main.tf b/infra/main.tf index 944bc11b7..6bbbffda4 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -294,7 +294,7 @@ resource "google_compute_global_forwarding_rule" "http" { } # It may take more than 2 minutes for the newly provisioned load balancer -# to forward requests to the Cloud Run service. The following data source +# to forward requests to the Cloud Run service. The following data source # allows for terraform apply to finish running when the end-point resolves data "http" "load_balancer_warm_up" { From 5716440d70df225569752cd1bc21e4160ef946ad Mon Sep 17 00:00:00 2001 From: rogerthatdev Date: Tue, 1 Aug 2023 11:39:00 -0700 Subject: [PATCH 11/11] dont start warmup until all lb resources created --- infra/main.tf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/infra/main.tf b/infra/main.tf index 6bbbffda4..3cd2e4cc3 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -305,8 +305,12 @@ data "http" "load_balancer_warm_up" { max_delay_ms = 20000 min_delay_ms = 20000 } - # Begin trying after forwarding rule is created. + # Begin trying after load balancer resources are created. depends_on = [ + google_compute_global_address.default, + google_compute_url_map.default, + google_compute_backend_service.default, + google_compute_target_http_proxy.default, google_compute_global_forwarding_rule.http ] }