forked from jonghall/ibmcloud-terraform-vpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lbaas.tf
54 lines (48 loc) · 1.92 KB
/
lbaas.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
#----------------------------------------------------------
# Create WebAppTier Load Balancer in zone 1 & Zone 2 of VPC
#----------------------------------------------------------
resource "ibm_is_lb" "webapptier-lb" {
name = "${var.vpc-name}-webapptier01-lb"
#resource_group = data.ibm_resource_group.group.id
subnets = [ibm_is_subnet.webapptier-subnet-zone1.id, ibm_is_subnet.webapptier-subnet-zone2.id]
}
resource "ibm_is_lb_listener" "webapptier-lb-listener" {
lb = ibm_is_lb.webapptier-lb.id
default_pool = element(split("/", ibm_is_lb_pool.webapptier-lb-pool.id), 1)
port = "80"
protocol = "http"
}
resource "ibm_is_lb_pool" "webapptier-lb-pool" {
lb = ibm_is_lb.webapptier-lb.id
name = "${var.vpc-name}-webapptier-lb-pool1"
protocol = "http"
algorithm = var.webapptier-lb-algorithm
health_delay = "5"
health_retries = "2"
health_timeout = "2"
health_type = "http"
health_monitor_url = "/"
}
#---------------------------------------------------------
# Add web from zone 1 and zone 2 to pool
#---------------------------------------------------------
resource "ibm_is_lb_pool_member" "webapptier-lb-pool-member-zone1" {
count = length(ibm_is_instance.webappserver-zone1)
lb = ibm_is_lb.webapptier-lb.id
pool = element(split("/", ibm_is_lb_pool.webapptier-lb-pool.id), 1)
port = "80"
target_address = element(
ibm_is_instance.webappserver-zone1.*.primary_network_interface.0.primary_ipv4_address,
count.index,
)
}
resource "ibm_is_lb_pool_member" "webapptier-lb-pool-member-zone2" {
count = length(ibm_is_instance.webappserver-zone2)
lb = ibm_is_lb.webapptier-lb.id
pool = element(split("/", ibm_is_lb_pool.webapptier-lb-pool.id), 1)
port = "80"
target_address = element(
ibm_is_instance.webappserver-zone2.*.primary_network_interface.0.primary_ipv4_address,
count.index,
)
}