Skip to content

Commit bf56f63

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. Change few names in AZ and AWS to keep all the same across CSP.
1 parent cb4dd4e commit bf56f63

8 files changed

Lines changed: 200 additions & 61 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/aws/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module "common_variables" {
4747
authorized_keys = var.authorized_keys
4848
authorized_user = var.admin_user
4949
monitoring_enabled = var.monitoring_enabled
50-
monitoring_srv_ip = var.monitoring_enabled ? local.monitoring_ip : ""
50+
monitoring_srv_ip = var.monitoring_enabled ? local.monitoring_srv_ip : ""
5151
hana_instance_number = var.hana_instance_number
5252
hana_cost_optimized_instance_number = var.hana_cost_optimized_instance_number
5353
hana_primary_site = var.hana_primary_site
@@ -183,7 +183,7 @@ module "monitoring" {
183183
vm_size = var.monitor_instancetype
184184
key_name = aws_key_pair.key-pair.key_name
185185
security_group_id = local.security_group_id
186-
monitoring_srv_ip = local.monitoring_ip
186+
monitoring_srv_ip = local.monitoring_srv_ip
187187
availability_zones = data.aws_availability_zones.available.names
188188
os_image = local.monitoring_os_image
189189
os_owner = local.monitoring_os_owner

terraform/aws/netaddress.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# This file is used to calculate and store in some local variables
1+
# This file is used to calculate and store in some locals (local variables)
22
# the IP addresses of all the machines.
33

44
locals {
5-
65
###################################################
76
###################################################
87
# R A N G E s
@@ -104,7 +103,7 @@ locals {
104103

105104
###################################################
106105
# INFRA
107-
monitoring_ip = (
106+
monitoring_srv_ip = (
108107
var.monitoring_srv_ip != "" ?
109108
var.monitoring_srv_ip :
110109
cidrhost(local.infra_subnet_address_range, local.ip_start)

terraform/azure/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module "common_variables" {
3535
authorized_keys = var.authorized_keys
3636
authorized_user = var.admin_user
3737
monitoring_enabled = var.monitoring_enabled
38-
monitoring_srv_ip = var.monitoring_enabled ? local.monitoring_ip : ""
38+
monitoring_srv_ip = var.monitoring_enabled ? local.monitoring_srv_ip : ""
3939
hana_hwcct = var.hwcct
4040
hana_instance_number = var.hana_instance_number
4141
hana_cost_optimized_instance_number = var.hana_cost_optimized_instance_number
@@ -199,7 +199,7 @@ module "monitoring" {
199199
storage_account = azurerm_storage_account.mytfstorageacc.primary_blob_endpoint
200200
monitoring_uri = local.monitoring_os_image_uri
201201
os_image = local.monitoring_os_image
202-
monitoring_srv_ip = local.monitoring_ip
202+
monitoring_srv_ip = local.monitoring_srv_ip
203203
}
204204

205205
module "iscsi_server" {

terraform/azure/netaddress.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ locals {
5757
###################################################
5858
# INFRA
5959
monitor_ip_start = 4
60-
monitoring_ip = (
60+
monitoring_srv_ip = (
6161
var.monitoring_srv_ip != "" ?
6262
var.monitoring_srv_ip :
6363
cidrhost(local.subnet_address_range, local.monitor_ip_start)

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: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
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+
ip_start = 4
37+
38+
###################################################
39+
# INFRA
40+
monitoring_srv_ip = (
41+
var.monitoring_srv_ip != "" ?
42+
var.monitoring_srv_ip :
43+
cidrhost(local.subnet_address_range, local.ip_start)
44+
)
45+
46+
iscsi_ip_start = local.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(var.hana_count) :
64+
cidrhost(local.subnet_address_range, ip_index + local.hana_ip_start)
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 = 6
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 = var.netweaver_ha_enabled ? max(local.netweaver_count, 3) : max(local.netweaver_count, 2)
140+
141+
netweaver_ip_start = 30
142+
netweaver_ips = (
143+
length(var.netweaver_ips) != 0 ?
144+
var.netweaver_ips :
145+
[
146+
for ip_index in range(local.netweaver_ip_start, local.netweaver_ip_start + local.netweaver_count) :
147+
cidrhost(local.subnet_address_range, ip_index)
148+
]
149+
)
150+
151+
# same subnet as netweaver hosts
152+
netweaver_virtual_ips_lb_xscs = (
153+
length(var.netweaver_virtual_ips) != 0 ?
154+
var.netweaver_virtual_ips :
155+
[
156+
for ip_index in range(local.netweaver_ip_start, local.netweaver_ip_start + local.netweaver_xscs_server_count) :
157+
cidrhost(local.subnet_address_range, ip_index + 4)
158+
]
159+
)
160+
161+
# different subnet as netweaver hosts
162+
netweaver_virtual_ips_lb_app = (
163+
length(var.netweaver_virtual_ips) != 0 ?
164+
var.netweaver_virtual_ips :
165+
[
166+
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) :
167+
cidrhost(cidrsubnet(local.subnet_address_range, -8, 0), 256 + ip_index + 4)
168+
]
169+
)
170+
171+
# different subnet as netweaver hosts
172+
netweaver_virtual_ips_route = (
173+
length(var.netweaver_virtual_ips) != 0 ?
174+
var.netweaver_virtual_ips :
175+
[
176+
for ip_index in range(local.netweaver_ip_start, local.netweaver_ip_start + local.netweaver_virtual_ips_count) :
177+
cidrhost(cidrsubnet(local.subnet_address_range, -8, 0), 256 + ip_index + 4)
178+
]
179+
)
180+
netweaver_virtual_ips = (
181+
var.netweaver_cluster_vip_mechanism == "load-balancer" ?
182+
concat(local.netweaver_virtual_ips_lb_xscs, local.netweaver_virtual_ips_lb_app) :
183+
local.netweaver_virtual_ips_route
184+
)
185+
}
186+

0 commit comments

Comments
 (0)