Skip to content

Commit 9082d29

Browse files
authored
VWAN | Added maintenance mode support (#22)
1 parent 9980561 commit 9082d29

File tree

6 files changed

+86
-4
lines changed

6 files changed

+86
-4
lines changed

modules/high_availability_existing_vnet/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module "example_module" {
3636
backend_subnet_name = "backend"
3737
frontend_IP_addresses = [5, 6, 7]
3838
backend_IP_addresses = [5, 6, 7]
39+
vips_names = []
3940
admin_password = "xxxxxxxxxxxx"
4041
smart_1_cloud_token_a = "xxxxxxxxxxxx"
4142
smart_1_cloud_token_b = "xxxxxxxxxxxx"
@@ -121,6 +122,7 @@ module "example_module" {
121122
| **use_public_ip_prefix** | Indicates whether the public IP resources will be deployed with public IP prefix | boolean | true;<br />false;<br />**Default:** false |
122123
| **create_public_ip_prefix** | Indicates whether the public IP prefix will be created or an existing one will be used | boolean | true;<br />false;<br />**Default:** false |
123124
| **existing_public_ip_prefix_id** | The existing public IP prefix resource ID | string | Existing public IP prefix resource ID<br /> |
125+
| **vips_names** | Names for additional Virtual IP addresses beyond the primary cluster VIP. Each name creates a corresponding public IP resource. | list(string) | **Default:** [] |
124126
| **admin_shell** | Enables selecting different admin shells | string | /etc/cli.sh;<br />/bin/bash;<br />/bin/csh;<br />/bin/tcsh;<br /> |
125127
| **serial_console_password_hash** | Optional parameter, used to enable serial console connection in case of SSH key as authentication type | string | |
126128
| **maintenance_mode_password_hash** | Maintenance mode password hash, relevant only for R81.20 and higher versions | string | |

modules/high_availability_existing_vnet/main.tf

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ resource "azurerm_public_ip_prefix" "public_ip_prefix" {
3535
name = "${module.common.resource_group_name}-ipprefix"
3636
location = module.common.resource_group_location
3737
resource_group_name = module.common.resource_group_name
38-
prefix_length = 30
38+
prefix_length = length(var.vips_names) > 4 ? 28 : length(var.vips_names) > 0 ? 29 : 30
3939
tags = merge(lookup(var.tags, "public-ip-prefix", {}), lookup(var.tags, "all", {}))
4040
}
4141

@@ -74,10 +74,24 @@ resource "azurerm_public_ip" "cluster-vip" {
7474
tags = merge(lookup(var.tags, "public-ip", {}), lookup(var.tags, "all", {}))
7575
}
7676

77+
resource "azurerm_public_ip" "vips" {
78+
count = length(var.vips_names)
79+
name = var.vips_names[count.index]
80+
location = module.common.resource_group_location
81+
resource_group_name = module.common.resource_group_name
82+
allocation_method = var.vnet_allocation_method
83+
sku = var.sku
84+
domain_name_label = "${lower(var.vips_names[count.index])}-${count.index}-vip-${random_id.random_id.hex}"
85+
public_ip_prefix_id = var.use_public_ip_prefix ? (var.create_public_ip_prefix ? azurerm_public_ip_prefix.public_ip_prefix[0].id : var.existing_public_ip_prefix_id) : null
86+
tags = merge(lookup(var.tags, "public-ip", {}), lookup(var.tags, "all", {}))
87+
}
88+
7789
resource "azurerm_network_interface" "nic_vip" {
7890
depends_on = [
7991
azurerm_public_ip.cluster-vip,
80-
azurerm_public_ip.public-ip]
92+
azurerm_public_ip.public-ip,
93+
azurerm_public_ip.vips,
94+
]
8195
name = "${var.cluster_name}1-eth0"
8296
location = module.common.resource_group_location
8397
resource_group_name = module.common.resource_group_name
@@ -100,6 +114,19 @@ resource "azurerm_network_interface" "nic_vip" {
100114
private_ip_address = cidrhost(data.azurerm_subnet.frontend.address_prefixes[0], var.frontend_IP_addresses[2])
101115
public_ip_address_id = azurerm_public_ip.cluster-vip.id
102116
}
117+
118+
dynamic "ip_configuration" {
119+
for_each = var.vips_names
120+
content {
121+
name = "cluster-vip-${index(var.vips_names, ip_configuration.value) + 1}"
122+
subnet_id = data.azurerm_subnet.frontend.id
123+
primary = false
124+
private_ip_address_allocation = var.vnet_allocation_method
125+
private_ip_address = cidrhost(data.azurerm_subnet.frontend.address_prefixes[0], 7 + index(var.vips_names, ip_configuration.value) + 1)
126+
public_ip_address_id = azurerm_public_ip.vips[index(var.vips_names, ip_configuration.value)].id
127+
}
128+
}
129+
103130
lifecycle {
104131
ignore_changes = [
105132
# Ignore changes to ip_configuration when Re-applying, e.g. because a cluster failover and associating the cluster- vip with the other member.

modules/high_availability_existing_vnet/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,16 @@ variable "tags" {
326326
description = "Assign tags by resource."
327327
type = map(map(string))
328328
default = {}
329+
}
330+
331+
variable "vips_names" {
332+
description = "Names to be used for the VIPs"
333+
type = list(string)
334+
default = []
335+
336+
# More than 10 VIPs may result in not enough available IPs available in IpPrefix
337+
validation {
338+
condition = length(var.vips_names) < 10
339+
error_message = "The number of VIPs must be less than 10."
340+
}
329341
}

modules/high_availability_new_vnet/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module "example_module" {
5757
use_public_ip_prefix = false
5858
create_public_ip_prefix = false
5959
existing_public_ip_prefix_id = ""
60+
vips_names = []
6061
admin_shell = "/etc/cli.sh"
6162
serial_console_password_hash = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
6263
maintenance_mode_password_hash = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@@ -122,6 +123,7 @@ module "example_module" {
122123
| **use_public_ip_prefix** | Indicates whether the public IP resources will be deployed with public IP prefix | boolean | true;<br />false;<br />**Default:** false |
123124
| **create_public_ip_prefix** | Indicates whether the public IP prefix will be created or an existing one will be used | boolean | true;<br />false;<br />**Default:** false |
124125
| **existing_public_ip_prefix_id** | The existing public IP prefix resource ID | string | Existing public IP prefix resource ID<br />**Default:** "" |
126+
| **vips_names** | Names for additional Virtual IP addresses beyond the primary cluster VIP. Each name creates a corresponding public IP resource. | list(string) | **Default:** [] |
125127
| **admin_shell** | Enables selecting different admin shells | string | /etc/cli.sh;<br />/bin/bash;<br />/bin/csh;<br />/bin/tcsh;<br />**Default:** "/etc/cli.sh" |
126128
| **serial_console_password_hash** | Optional parameter to enable serial console connection in case of SSH key as authentication type | string | |
127129
| **maintenance_mode_password_hash**| Maintenance mode password hash, relevant only for R81.20 and higher versions | string | |

modules/high_availability_new_vnet/main.tf

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "azurerm_public_ip_prefix" "public_ip_prefix" {
5656
name = "${module.common.resource_group_name}-ipprefix"
5757
location = module.common.resource_group_location
5858
resource_group_name = module.common.resource_group_name
59-
prefix_length = 30
59+
prefix_length = length(var.vips_names) > 4 ? 28 : length(var.vips_names) > 0 ? 29 : 30
6060
tags = merge(lookup(var.tags, "public-ip-prefix", {}), lookup(var.tags, "all", {}))
6161
}
6262

@@ -83,10 +83,24 @@ resource "azurerm_public_ip" "cluster-vip" {
8383
tags = merge(lookup(var.tags, "public-ip", {}), lookup(var.tags, "all", {}))
8484
}
8585

86+
resource "azurerm_public_ip" "vips" {
87+
count = length(var.vips_names)
88+
name = var.vips_names[count.index]
89+
location = module.common.resource_group_location
90+
resource_group_name = module.common.resource_group_name
91+
allocation_method = module.vnet.allocation_method
92+
sku = var.sku
93+
domain_name_label = "${lower(var.vips_names[count.index])}-${count.index}-vip-${random_id.random_id.hex}"
94+
public_ip_prefix_id = var.use_public_ip_prefix ? (var.create_public_ip_prefix ? azurerm_public_ip_prefix.public_ip_prefix[0].id : var.existing_public_ip_prefix_id) : null
95+
tags = merge(lookup(var.tags, "public-ip", {}), lookup(var.tags, "all", {}))
96+
}
97+
8698
resource "azurerm_network_interface" "nic_vip" {
8799
depends_on = [
88100
azurerm_public_ip.cluster-vip,
89-
azurerm_public_ip.public-ip]
101+
azurerm_public_ip.public-ip,
102+
azurerm_public_ip.vips,
103+
]
90104
name = "${var.cluster_name}1-eth0"
91105
location = module.common.resource_group_location
92106
resource_group_name = module.common.resource_group_name
@@ -109,6 +123,19 @@ resource "azurerm_network_interface" "nic_vip" {
109123
private_ip_address = cidrhost(module.vnet.subnet_prefixes[0], 7)
110124
public_ip_address_id = azurerm_public_ip.cluster-vip.id
111125
}
126+
127+
dynamic "ip_configuration" {
128+
for_each = var.vips_names
129+
content {
130+
name = "cluster-vip-${index(var.vips_names, ip_configuration.value) + 1}"
131+
subnet_id = module.vnet.vnet_subnets[0]
132+
primary = false
133+
private_ip_address_allocation = module.vnet.allocation_method
134+
private_ip_address = cidrhost(module.vnet.subnet_prefixes[0], 7 + index(var.vips_names, ip_configuration.value) + 1)
135+
public_ip_address_id = azurerm_public_ip.vips[index(var.vips_names, ip_configuration.value)].id
136+
}
137+
}
138+
112139
lifecycle {
113140
ignore_changes = [
114141
# Ignore changes to ip_configuration when Re-applying, e.g. because a cluster failover and associating the cluster- vip with the other member.

modules/high_availability_new_vnet/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,16 @@ variable "tags" {
326326
description = "Assign tags by resource."
327327
type = map(map(string))
328328
default = {}
329+
}
330+
331+
variable "vips_names" {
332+
description = "Names to be used for the VIPs"
333+
type = list(string)
334+
default = []
335+
336+
# More than 10 VIPs may result in not enough available IPs available in IpPrefix
337+
validation {
338+
condition = length(var.vips_names) < 10
339+
error_message = "The number of VIPs must be less than 10."
340+
}
329341
}

0 commit comments

Comments
 (0)