Skip to content

Commit dbb551e

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

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

.terraform-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.3.0

main.tf

+23-4
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

+9
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ variable "https_redirect" {
275275
default = false
276276
}
277277

278+
variable "https_redirect_domains" {
279+
type = list(string)
280+
default = []
281+
validation {
282+
condition = var.https_redirect_domains == [] || !(length(var.https_redirect_domains) == 1 && var.https_redirect_domains[0] == "")
283+
error_message = "The variable \"https_redirect_domains\" must not contain an empty string. Use an empty list ([]) if no domains are provided."
284+
}
285+
}
286+
278287
variable "random_certificate_suffix" {
279288
description = "Bool to enable/disable random certificate name generation. Set and keep this to true if you need to change the SSL cert."
280289
type = bool

versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
terraform {
18-
required_version = ">= 1.3"
18+
required_version = ">= 1.2.9"
1919
required_providers {
2020

2121
google = {

0 commit comments

Comments
 (0)