This repository has been archived by the owner on Mar 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.load-balancer.tf
99 lines (84 loc) · 2.66 KB
/
app.load-balancer.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# See https://cloud.google.com/load-balancing/docs/https/
resource "google_compute_global_address" "app-lb" {
name = "${var.basename}-app-lb"
}
resource "google_dns_record_set" "app-lb" {
count = length(local.app_load_balancer_hostnames)
name = format(
"%s%s.%s.",
element(local.app_load_balancer_hostnames, count.index),
var.basename,
var.basedomain
)
type = "A"
ttl = 3600
managed_zone = google_dns_managed_zone.main.name
rrdatas = [
google_compute_global_address.app-lb.address
]
}
# --------------------------------
# Forwarding rules configuration
resource "google_compute_global_forwarding_rule" "app-https" {
name = "${var.basename}-app-https"
target = google_compute_target_https_proxy.app.self_link
ip_address = google_compute_global_address.app-lb.address
port_range = 443
}
resource "google_compute_global_forwarding_rule" "app-http" {
name = "${var.basename}-app-http"
target = google_compute_target_http_proxy.app.self_link
ip_address = google_compute_global_address.app-lb.address
port_range = 80
}
# --------------------------------
# Target proxies configuration
resource "google_compute_target_https_proxy" "app" {
name = "${var.basename}-app"
url_map = google_compute_url_map.app.self_link
ssl_certificates = [google_compute_managed_ssl_certificate.app.self_link]
}
resource "google_compute_target_http_proxy" "app" {
name = "${var.basename}-app"
url_map = google_compute_url_map.app.self_link
}
# --------------------------------
# URL map configuration
resource "google_compute_url_map" "app" {
name = "${var.basename}-app"
default_service = google_compute_backend_service.app.self_link
host_rule {
hosts = ["${var.basename}.${var.basedomain}"]
path_matcher = "allpaths"
}
path_matcher {
name = "allpaths"
default_service = google_compute_backend_service.app.self_link
path_rule {
paths = ["/*"]
service = google_compute_backend_service.app.self_link
}
}
}
# --------------------------------
# Backend configuration
resource "google_compute_backend_service" "app" {
name = "${var.basename}-app"
backend {
group = google_compute_instance_group.app.self_link
}
port_name = "http"
protocol = "HTTP"
timeout_sec = 30
health_checks = [
google_compute_http_health_check.app.self_link
]
security_policy = google_compute_security_policy.main.self_link
}
resource "google_compute_http_health_check" "app" {
name = "${var.basename}-app"
request_path = "/"
port = 80
check_interval_sec = 10
timeout_sec = 10
}