forked from marcelo-ochoa/oci-swarm-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadbalancer.tf
102 lines (89 loc) · 3.48 KB
/
loadbalancer.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
100
101
102
# Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#
resource "oci_load_balancer_load_balancer" "oci_swarm_lb" {
compartment_id = (var.lb_compartment_ocid != "") ? var.lb_compartment_ocid : var.compartment_ocid
display_name = "oci-swarm-${random_string.deploy_id.result}"
shape = var.lb_shape
subnet_ids = [oci_core_subnet.oci_swarm_lb_subnet.id]
is_private = "false"
freeform_tags = local.common_tags
# Choose flexible as shape in var.lb_shape
shape_details {
#Required
maximum_bandwidth_in_mbps = 10
minimum_bandwidth_in_mbps = 10
}
}
resource "oci_load_balancer_backend_set" "oci_swarm_bes" {
name = "oci-swarm-${random_string.deploy_id.result}"
load_balancer_id = oci_load_balancer_load_balancer.oci_swarm_lb.id
policy = "IP_HASH"
health_checker {
port = "80"
protocol = "HTTP"
response_body_regex = ".*"
url_path = "/whoami"
return_code = 200
interval_ms = 5000
timeout_in_millis = 2000
retries = 10
}
}
resource "oci_load_balancer_backend" "oci-swarm-be" {
load_balancer_id = oci_load_balancer_load_balancer.oci_swarm_lb.id
backendset_name = oci_load_balancer_backend_set.oci_swarm_bes.name
ip_address = element(oci_core_instance.app_instance.*.private_ip, count.index)
port = 80
backup = false
drain = false
offline = false
weight = 1
count = (var.num_nodes > 2) ? 2 : var.num_nodes
}
resource "oci_load_balancer_backend_set" "oci_swarm_bes_ssl" {
name = "oci-swarm-ssl-${random_string.deploy_id.result}"
load_balancer_id = oci_load_balancer_load_balancer.oci_swarm_lb.id
policy = "IP_HASH"
health_checker {
port = "80"
protocol = "HTTP"
response_body_regex = ".*"
url_path = "/whoami"
return_code = 200
interval_ms = 5000
timeout_in_millis = 2000
retries = 10
}
}
resource "oci_load_balancer_backend" "oci-swarm-be_ssl" {
load_balancer_id = oci_load_balancer_load_balancer.oci_swarm_lb.id
backendset_name = oci_load_balancer_backend_set.oci_swarm_bes_ssl.name
ip_address = element(oci_core_instance.app_instance.*.private_ip, count.index)
port = 443
backup = false
drain = false
offline = false
weight = 1
count = (var.num_nodes > 2) ? 2 : var.num_nodes
}
resource "oci_load_balancer_listener" "oci_swarm_listener_80" {
load_balancer_id = oci_load_balancer_load_balancer.oci_swarm_lb.id
default_backend_set_name = oci_load_balancer_backend_set.oci_swarm_bes.name
name = "oci-swarm-${random_string.deploy_id.result}-80"
port = 80
protocol = "TCP"
connection_configuration {
idle_timeout_in_seconds = "30"
}
}
resource "oci_load_balancer_listener" "oci_swarm_listener_443" {
load_balancer_id = oci_load_balancer_load_balancer.oci_swarm_lb.id
default_backend_set_name = oci_load_balancer_backend_set.oci_swarm_bes_ssl.name
name = "oci-swarm-${random_string.deploy_id.result}-443"
port = 443
protocol = "TCP"
connection_configuration {
idle_timeout_in_seconds = "30"
}
}