Skip to content

Commit 3021ef3

Browse files
committed
Move all the GCP network configuration
Move all the terraform locals about networking to a dedicated file in the GCP project. This follow same aproach already implemented for Azure and AWS.
1 parent 5da906a commit 3021ef3

4 files changed

Lines changed: 197 additions & 53 deletions

File tree

cspell.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@
2828
"isreg",
2929
"keygen",
3030
"logd",
31+
"netweaver",
3132
"noqa",
3233
"nosum",
3334
"numluns",
3435
"nvme",
3536
"publickey",
37+
"pytest",
38+
"PYTHONPATH",
39+
"qesap",
3640
"Quickstart",
3741
"reuseaddr",
3842
"rsyslog",
@@ -45,10 +49,7 @@
4549
"usrsaplv",
4650
"usrsapvg",
4751
"venv",
48-
"yast",
49-
"qesap",
50-
"PYTHONPATH",
51-
"pytest"
52+
"yast"
5253
],
5354
"languageSettings": [
5455
{

terraform/gcp/infrastructure.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ locals {
1616

1717
network_link = var.vpc_name == "" ? google_compute_network.ha_network.0.self_link : format(
1818
"https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", var.project, var.vpc_name)
19-
vpc_name = var.vpc_name == "" ? google_compute_network.ha_network.0.name : var.vpc_name
20-
subnet_name = var.subnet_name == "" ? google_compute_subnetwork.ha_subnet.0.name : var.subnet_name
21-
subnet_address_range = var.subnet_name == "" ? var.ip_cidr_range : (var.ip_cidr_range == "" ? data.google_compute_subnetwork.current-subnet.0.ip_cidr_range : var.ip_cidr_range)
19+
vpc_name = var.vpc_name == "" ? google_compute_network.ha_network.0.name : var.vpc_name
20+
subnet_name = var.subnet_name == "" ? google_compute_subnetwork.ha_subnet.0.name : var.subnet_name
2221

2322
create_firewall = var.create_firewall_rules ? 1 : 0
2423
ibsm_count = (var.ibsm_vpc_name != "" && var.ibsm_subnet_name != "" && var.ibsm_subnet_region != "") ? 1 : 0

terraform/gcp/main.tf

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,7 @@
1-
# This locals entry is used to store the IP addresses of all the machines.
2-
# Autogenerated addresses example based in 10.0.0.0/24
3-
# Iscsi server: 10.0.0.4
4-
# Monitoring: 10.0.0.5
5-
# Hana ips: 10.0.0.10, 10.0.0.11
6-
# Hana cluster vip: 10.0.0.12
7-
# Hana cluster vip secondary: 10.0.0.13
8-
# DRBD ips: 10.0.0.20, 10.0.0.21
9-
# DRBD cluster vip: 10.0.0.22
10-
# Netweaver ips: 10.0.0.30, 10.0.0.31, 10.0.0.32, 10.0.0.33
11-
# Netweaver virtual ips: 10.0.0.34, 10.0.0.35, 10.0.0.36, 10.0.0.37
12-
# If the addresses are provided by the user they will always have preference
131
locals {
14-
monitoring_srv_ip = var.monitoring_srv_ip != "" ? var.monitoring_srv_ip : cidrhost(local.subnet_address_range, 4)
15-
iscsi_ip_start = 5
16-
iscsi_ips = length(var.iscsi_ips) != 0 ? var.iscsi_ips : [for ip_index in range(local.iscsi_ip_start, var.iscsi_count + local.iscsi_ip_start) : cidrhost(local.subnet_address_range, ip_index)]
17-
18-
hana_ip_start = 10
19-
hana_ips = length(var.hana_ips) != 0 ? var.hana_ips : [for ip_index in range(local.hana_ip_start, local.hana_ip_start + var.hana_count) : cidrhost(local.subnet_address_range, ip_index)]
20-
21-
# Virtual IP addresses if a load balancer is used. In this case the virtual ip address belongs to the same subnet than the machines
22-
hana_cluster_vip_lb = var.hana_cluster_vip != "" ? var.hana_cluster_vip : cidrhost(local.subnet_address_range, local.hana_ip_start + var.hana_count)
23-
hana_cluster_vip_secondary_lb = var.hana_cluster_vip_secondary != "" ? var.hana_cluster_vip_secondary : cidrhost(local.subnet_address_range, local.hana_ip_start + var.hana_count + 1)
24-
25-
# Virtual IP addresses if a route is used. In this case the virtual ip address belongs to a different subnet than the machines
26-
hana_cluster_vip_route = var.hana_cluster_vip != "" ? var.hana_cluster_vip : cidrhost(cidrsubnet(local.subnet_address_range, -8, 0), 256 + local.hana_ip_start + var.hana_count)
27-
hana_cluster_vip_secondary_route = var.hana_cluster_vip_secondary != "" ? var.hana_cluster_vip_secondary : cidrhost(cidrsubnet(local.subnet_address_range, -8, 0), 256 + local.hana_ip_start + var.hana_count + 1)
28-
29-
# Select the final virtual ip address
30-
hana_cluster_vip = var.hana_cluster_vip_mechanism == "load-balancer" ? local.hana_cluster_vip_lb : local.hana_cluster_vip_route
31-
hana_cluster_vip_secondary = var.hana_cluster_vip_mechanism == "load-balancer" ? local.hana_cluster_vip_secondary_lb : local.hana_cluster_vip_secondary_route
32-
33-
# 2 is hardcoded for drbd because we always deploy 4 machines
34-
drbd_ip_start = 20
35-
drbd_ips = length(var.drbd_ips) != 0 ? var.drbd_ips : [for ip_index in range(local.drbd_ip_start, local.drbd_ip_start + 2) : cidrhost(local.subnet_address_range, ip_index)]
36-
# Virtual IP addresses if a route is used. In this case the virtual ip address belongs to a different subnet than the machines
37-
drbd_cluster_vip_lb = var.drbd_cluster_vip != "" ? var.drbd_cluster_vip : cidrhost(local.subnet_address_range, local.drbd_ip_start + 2)
38-
drbd_cluster_vip_route = var.drbd_cluster_vip != "" ? var.drbd_cluster_vip : cidrhost(cidrsubnet(local.subnet_address_range, -8, 0), 256 + local.drbd_ip_start + 2)
39-
drbd_cluster_vip = var.drbd_cluster_vip_mechanism == "load-balancer" ? local.drbd_cluster_vip_lb : local.drbd_cluster_vip_route
402

413
netweaver_xscs_server_count = var.netweaver_enabled ? (var.netweaver_ha_enabled ? 2 : 1) : 0
424
netweaver_count = var.netweaver_enabled ? local.netweaver_xscs_server_count + var.netweaver_app_server_count : 0
43-
netweaver_virtual_ips_count = var.netweaver_ha_enabled ? max(local.netweaver_count, 3) : max(local.netweaver_count, 2) # We need at least 2 virtual ips, if ASCS and PAS are in the same machine
44-
45-
netweaver_ip_start = 30
46-
netweaver_ips = length(var.netweaver_ips) != 0 ? var.netweaver_ips : [for ip_index in range(local.netweaver_ip_start, local.netweaver_ip_start + local.netweaver_count) : cidrhost(local.subnet_address_range, ip_index)]
47-
netweaver_virtual_ips_lb_xscs = length(var.netweaver_virtual_ips) != 0 ? var.netweaver_virtual_ips : [for ip_index in range(local.netweaver_ip_start, local.netweaver_ip_start + local.netweaver_xscs_server_count) : cidrhost(local.subnet_address_range, ip_index + 4)] # same subnet as netweaver hosts
48-
netweaver_virtual_ips_lb_app = length(var.netweaver_virtual_ips) != 0 ? var.netweaver_virtual_ips : [for ip_index in range(local.netweaver_ip_start + local.netweaver_xscs_server_count, local.netweaver_ip_start + local.netweaver_xscs_server_count + var.netweaver_app_server_count) : cidrhost(cidrsubnet(local.subnet_address_range, -8, 0), 256 + ip_index + 4)] # different subnet as netweaver hosts
49-
netweaver_virtual_ips_route = length(var.netweaver_virtual_ips) != 0 ? var.netweaver_virtual_ips : [for ip_index in range(local.netweaver_ip_start, local.netweaver_ip_start + local.netweaver_virtual_ips_count) : cidrhost(cidrsubnet(local.subnet_address_range, -8, 0), 256 + ip_index + 4)] # different subnet as netweaver hosts
50-
netweaver_virtual_ips = var.netweaver_cluster_vip_mechanism == "load-balancer" ? concat(local.netweaver_virtual_ips_lb_xscs, local.netweaver_virtual_ips_lb_app) : local.netweaver_virtual_ips_route
515

526
# Check if iscsi server has to be created
537
use_sbd = var.hana_cluster_fencing_mechanism == "sbd" || var.drbd_cluster_fencing_mechanism == "sbd" || var.netweaver_cluster_fencing_mechanism == "sbd"

terraform/gcp/netaddress.tf

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# This file is used to calculate and store in some locals (local variables)
2+
# the IP addresses of all the machines.
3+
4+
locals {
5+
###################################################
6+
###################################################
7+
# R A N G E s
8+
###################################################
9+
###################################################
10+
# There is a hierarchy of nested ranges
11+
12+
subnet_address_range = (
13+
var.subnet_name == "" ?
14+
var.ip_cidr_range :
15+
var.ip_cidr_range == "" ? data.google_compute_subnetwork.current-subnet.0.ip_cidr_range : var.ip_cidr_range
16+
)
17+
18+
###################################################
19+
###################################################
20+
# I P s
21+
###################################################
22+
###################################################
23+
# This locals entry is used to store the IP addresses of all the machines.
24+
# Autogenerated addresses example based in 10.0.0.0/24
25+
# Iscsi server: 10.0.0.4
26+
# Monitoring: 10.0.0.5
27+
# Hana ips: 10.0.0.10, 10.0.0.11
28+
# Hana cluster vip: 10.0.0.12
29+
# Hana cluster vip secondary: 10.0.0.13
30+
# DRBD ips: 10.0.0.20, 10.0.0.21
31+
# DRBD cluster vip: 10.0.0.22
32+
# Netweaver ips: 10.0.0.30, 10.0.0.31, 10.0.0.32, 10.0.0.33
33+
# Netweaver virtual ips: 10.0.0.34, 10.0.0.35, 10.0.0.36, 10.0.0.37
34+
# If the addresses are provided by the user they will always have preference
35+
36+
37+
###################################################
38+
# INFRA
39+
monitor_ip_start = 4
40+
monitoring_srv_ip = (
41+
var.monitoring_srv_ip != "" ?
42+
var.monitoring_srv_ip :
43+
cidrhost(local.subnet_address_range, local.monitor_ip_start)
44+
)
45+
46+
iscsi_ip_start = local.monitor_ip_start + 1
47+
iscsi_ips = (
48+
length(var.iscsi_ips) != 0 ?
49+
var.iscsi_ips :
50+
[
51+
for ip_index in range(local.iscsi_ip_start, var.iscsi_count + local.iscsi_ip_start) :
52+
cidrhost(local.subnet_address_range, ip_index)
53+
]
54+
)
55+
56+
###################################################
57+
# HANA
58+
hana_ip_start = 10
59+
hana_ips = (
60+
length(var.hana_ips) != 0 ?
61+
var.hana_ips :
62+
[
63+
for ip_index in range(local.hana_ip_start, local.hana_ip_start + var.hana_count) :
64+
cidrhost(local.subnet_address_range, ip_index)
65+
]
66+
)
67+
68+
# Virtual IP addresses if a load balancer is used. In this case the virtual ip address belongs to the same subnet than the machines
69+
hana_cluster_vip_lb = (
70+
var.hana_cluster_vip != "" ?
71+
var.hana_cluster_vip :
72+
cidrhost(local.subnet_address_range, local.hana_ip_start + var.hana_count)
73+
)
74+
hana_cluster_vip_secondary_lb = (
75+
var.hana_cluster_vip_secondary != "" ?
76+
var.hana_cluster_vip_secondary :
77+
cidrhost(local.subnet_address_range, local.hana_ip_start + var.hana_count + 1)
78+
)
79+
80+
# Virtual IP addresses if a route is used. In this case the virtual ip address belongs to a different subnet than the machines
81+
hana_cluster_vip_route = (
82+
var.hana_cluster_vip != "" ?
83+
var.hana_cluster_vip :
84+
cidrhost(cidrsubnet(local.subnet_address_range, -8, 0), 256 + local.hana_ip_start + var.hana_count)
85+
)
86+
hana_cluster_vip_secondary_route = (
87+
var.hana_cluster_vip_secondary != "" ?
88+
var.hana_cluster_vip_secondary :
89+
cidrhost(cidrsubnet(local.subnet_address_range, -8, 0), 256 + local.hana_ip_start + var.hana_count + 1)
90+
)
91+
92+
# Select the final virtual ip address
93+
hana_cluster_vip = (
94+
var.hana_cluster_vip_mechanism == "load-balancer" ?
95+
local.hana_cluster_vip_lb :
96+
local.hana_cluster_vip_route
97+
)
98+
99+
hana_cluster_vip_secondary = (
100+
var.hana_cluster_vip_mechanism == "load-balancer" ?
101+
local.hana_cluster_vip_secondary_lb :
102+
local.hana_cluster_vip_secondary_route
103+
)
104+
105+
###################################################
106+
# DRBD
107+
# 2 is hardcoded for drbd because we always deploy 4 machines
108+
drbd_ip_start = 20
109+
drbd_ips = (
110+
length(var.drbd_ips) != 0 ?
111+
var.drbd_ips :
112+
[
113+
for ip_index in range(local.drbd_ip_start, local.drbd_ip_start + 2) :
114+
cidrhost(local.subnet_address_range, ip_index)
115+
]
116+
)
117+
# Virtual IP addresses if a route is used. In this case the virtual ip address belongs to a different subnet than the machines
118+
drbd_cluster_vip_lb = (
119+
var.drbd_cluster_vip != "" ?
120+
var.drbd_cluster_vip :
121+
cidrhost(local.subnet_address_range, local.drbd_ip_start + 2)
122+
)
123+
124+
drbd_cluster_vip_route = (
125+
var.drbd_cluster_vip != "" ?
126+
var.drbd_cluster_vip :
127+
cidrhost(cidrsubnet(local.subnet_address_range, -8, 0), 256 + local.drbd_ip_start + 2)
128+
)
129+
130+
drbd_cluster_vip = (
131+
var.drbd_cluster_vip_mechanism == "load-balancer" ?
132+
local.drbd_cluster_vip_lb :
133+
local.drbd_cluster_vip_route
134+
)
135+
136+
###################################################
137+
# NETWEAVER
138+
# We need at least 2 virtual ips, if ASCS and PAS are in the same machine
139+
netweaver_virtual_ips_count = (
140+
var.netweaver_ha_enabled ?
141+
max(local.netweaver_count, 3) :
142+
max(local.netweaver_count, 2)
143+
)
144+
145+
netweaver_ip_start = 30
146+
netweaver_ips = (
147+
length(var.netweaver_ips) != 0 ?
148+
var.netweaver_ips :
149+
[
150+
for ip_index in range(local.netweaver_ip_start, local.netweaver_ip_start + local.netweaver_count) :
151+
cidrhost(local.subnet_address_range, ip_index)
152+
]
153+
)
154+
155+
# same subnet as netweaver hosts
156+
netweaver_virtual_ips_lb_xscs = (
157+
length(var.netweaver_virtual_ips) != 0 ?
158+
var.netweaver_virtual_ips :
159+
[
160+
for ip_index in range(local.netweaver_ip_start, local.netweaver_ip_start + local.netweaver_xscs_server_count) :
161+
cidrhost(local.subnet_address_range, ip_index + 4)
162+
]
163+
)
164+
165+
# different subnet as netweaver hosts
166+
netweaver_virtual_ips_lb_app = (
167+
length(var.netweaver_virtual_ips) != 0 ?
168+
var.netweaver_virtual_ips :
169+
[
170+
for ip_index in range(local.netweaver_ip_start + local.netweaver_xscs_server_count, local.netweaver_ip_start + local.netweaver_xscs_server_count + var.netweaver_app_server_count) :
171+
cidrhost(cidrsubnet(local.subnet_address_range, -8, 0), 256 + ip_index + 4)
172+
]
173+
)
174+
175+
# different subnet as netweaver hosts
176+
netweaver_virtual_ips_route = (
177+
length(var.netweaver_virtual_ips) != 0 ?
178+
var.netweaver_virtual_ips :
179+
[
180+
for ip_index in range(local.netweaver_ip_start, local.netweaver_ip_start + local.netweaver_virtual_ips_count) :
181+
cidrhost(cidrsubnet(local.subnet_address_range, -8, 0), 256 + ip_index + 4)
182+
]
183+
)
184+
netweaver_virtual_ips = (
185+
var.netweaver_cluster_vip_mechanism == "load-balancer" ?
186+
concat(local.netweaver_virtual_ips_lb_xscs, local.netweaver_virtual_ips_lb_app) :
187+
local.netweaver_virtual_ips_route
188+
)
189+
}
190+

0 commit comments

Comments
 (0)