-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathnetaddress.tf
More file actions
183 lines (169 loc) · 7.02 KB
/
netaddress.tf
File metadata and controls
183 lines (169 loc) · 7.02 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# This file is used to calculate and store in some locals (local variables)
# the IP addresses of all the machines.
locals {
###################################################
###################################################
# R A N G E s
###################################################
###################################################
# There is a hierarchy of nested ranges
# - all of them belong and fit in the vpc_address_range
# - the vpc_address_range accomodates 4 subranges: infra, hana, netweaver, drbd
# - infra is always present, it has 8 address (but first 4 are reserved by AWS).
# Infra range fits the IPs for monitor and iscsi machines.
# - hana is not a single range but a set of ranges, one for each hana_count (so eventually it can be missing as count can be zero).
# Hana ranges are placed after the infra one.
# They are 8 address wide (but first 4 are reserved by AWS)
# - netweaver are always 2 ranges. Starting point if after infra and hana (using hana_count)
# All addresses are calculated starting from value of vpc_address_range if provided,
# otherwise from the range assigned by default by AWS to the current-vpc.
vpc_address_range = (
var.vpc_id == "" ?
var.vpc_address_range :
var.vpc_address_range == "" ? data.aws_vpc.current-vpc.0.cidr_block : var.vpc_address_range
)
###################################################
# INFRA
infra_subnet_address_range_size = 3
infra_subnet_offset = 0
infra_subnet_address_range = (
var.infra_subnet_address_range != "" ?
var.infra_subnet_address_range :
# range of 8 IPs starting from the beginning of vpc_address_range
cidrsubnet(local.vpc_address_range, local.infra_subnet_address_range_size, local.infra_subnet_offset)
)
###################################################
# HANA
hana_subnet_address_range_size = 3
hana_subnet_offset = local.infra_subnet_offset + 1
hana_subnet_address_range = (
length(var.hana_subnet_address_range) != 0 ?
var.hana_subnet_address_range :
[
for index in range(var.hana_count) :
cidrsubnet(local.vpc_address_range, local.hana_subnet_address_range_size, index + local.hana_subnet_offset)
]
)
###################################################
# NETWEAVER
# The 2 is hardcoded because we create 2 subnets for NW always
netweaver_subnet_address_range_size = 3
netweaver_subnet_offset = local.hana_subnet_offset + var.hana_count
netweaver_subnet_count = 2
netweaver_subnet_address_range = (
length(var.netweaver_subnet_address_range) != 0 ?
var.netweaver_subnet_address_range :
[
for index in range(local.netweaver_subnet_count) :
cidrsubnet(local.vpc_address_range, local.netweaver_subnet_address_range_size, index + local.netweaver_subnet_offset)
]
)
###################################################
# DRBD
# The 2 is hardcoded considering we create 2 subnets for NW always
drbd_subnet_address_range_size = 3
drbd_subnet_offset = local.netweaver_subnet_offset + local.netweaver_subnet_count
drbd_subnet_count = 2
drbd_subnet_address_range = (
length(var.drbd_subnet_address_range) != 0 ?
var.drbd_subnet_address_range :
[
for index in range(local.drbd_subnet_count) :
cidrsubnet(local.vpc_address_range, local.drbd_subnet_address_range_size, index + local.drbd_subnet_offset)
]
)
###################################################
###################################################
# I P s
###################################################
###################################################
# The next locals are used to map the ip index with the subnet range (something like python enumerate method)
# The first four IP addresses and the last IP address in each subnet CIDR block are reserved to AWS.
# Autogenerated addresses example based in 10.0.0.0/16
# Monitoring: 10.0.0.4
# Iscsi server: 10.0.0.5
# Hana ips: 10.0.1.10, 10.0.2.11 (hana machines must be in different subnets)
# Hana cluster vip: 192.168.1.10 (virtual ip address must be in a different range than the vpc)
# Hana cluster vip secondary: 192.168.1.11
# Netweaver ips: 10.0.3.30, 10.0.4.31, 10.0.3.32, 10.0.4.33 (netweaver ASCS and ERS must be in different subnets)
# Netweaver virtual ips: 192.168.1.30, 192.168.1.31, 192.168.1.32, 192.168.1.33 (virtual ip addresses must be in a different range than the vpc)
# DRBD ips: 10.0.5.20, 10.0.6.21
# DRBD cluster vip: 192.168.1.20 (virtual ip address must be in a different range than the vpc)
# If the addresses are provided by the user will always have preference
# The first four IP addresses and the last IP address in each subnet CIDR block are reserved to AWS.
ip_start = 4
###################################################
# INFRA
monitoring_srv_ip = (
var.monitoring_srv_ip != "" ?
var.monitoring_srv_ip :
cidrhost(local.infra_subnet_address_range, local.ip_start)
)
iscsi_ip_start = local.ip_start + 1
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.infra_subnet_address_range, ip_index)
]
)
###################################################
# HANA
hana_ips = (
length(var.hana_ips) != 0 ?
var.hana_ips :
[
for ip_index in range(var.hana_count) :
cidrhost(element(local.hana_subnet_address_range, ip_index), ip_index + local.ip_start)
]
)
hana_cluster_vip = (
var.hana_cluster_vip != "" ?
var.hana_cluster_vip :
cidrhost(var.virtual_address_range, local.ip_start)
)
hana_cluster_vip_secondary = (
var.hana_cluster_vip_secondary != "" ?
var.hana_cluster_vip_secondary :
cidrhost(var.virtual_address_range, local.ip_start + 1)
)
###################################################
# NETWEAVER
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
)
netweaver_ips = (
length(var.netweaver_ips) != 0 ?
var.netweaver_ips :
[
for ip_index in range(local.netweaver_count) :
cidrhost(element(local.netweaver_subnet_address_range, ip_index % 2), ip_index + local.ip_start)
]
)
netweaver_virtual_ips = (
length(var.netweaver_virtual_ips) != 0 ?
var.netweaver_virtual_ips :
[
for ip_index in range(local.ip_start, local.ip_start + local.netweaver_virtual_ips_count) :
cidrhost(var.virtual_address_range, ip_index)
]
)
###################################################
# DRBD
drbd_ips = (
length(var.drbd_ips) != 0 ?
var.drbd_ips :
[
for ip_index in range(2) :
cidrhost(element(local.drbd_subnet_address_range, ip_index), ip_index + local.ip_start)
]
)
drbd_cluster_vip = (
var.drbd_cluster_vip != "" ?
var.drbd_cluster_vip :
cidrhost(var.virtual_address_range, local.ip_start)
)
}