Skip to content

Commit 47db538

Browse files
author
Srinivas Arnepalli
committed
feat: Add support for allowed list of domains for https redirect
1 parent 279c8e8 commit 47db538

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

main.tf

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,29 @@ resource "google_compute_url_map" "https_redirect" {
174174
project = var.project
175175
count = var.https_redirect ? 1 : 0
176176
name = "${var.name}-https-redirect"
177-
default_url_redirect {
178-
https_redirect = true
179-
redirect_response_code = "MOVED_PERMANENTLY_DEFAULT"
180-
strip_query = false
177+
178+
host_rule {
179+
hosts = length(var.https_redirect_domains) > 0 ? var.https_redirect_domains : ["*"]
180+
path_matcher = "https-redirect-matcher"
181+
}
182+
path_matcher {
183+
name = "https-redirect-matcher"
184+
default_url_redirect {
185+
https_redirect = true
186+
redirect_response_code = "MOVED_PERMANENTLY_DEFAULT"
187+
strip_query = false
188+
}
189+
}
190+
default_route_action {
191+
weighted_backend_services {
192+
backend_service = google_compute_backend_service.default[keys(var.backends)[0]].self_link
193+
}
194+
fault_injection_policy {
195+
abort {
196+
http_status = 404
197+
percentage = 100
198+
}
199+
}
181200
}
182201
}
183202

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ variable "https_redirect" {
275275
default = false
276276
}
277277

278+
variable "https_redirect_domains" {
279+
type = list(string)
280+
default = []
281+
}
282+
278283
variable "random_certificate_suffix" {
279284
description = "Bool to enable/disable random certificate name generation. Set and keep this to true if you need to change the SSL cert."
280285
type = bool

0 commit comments

Comments
 (0)