|
| 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