Skip to content

Commit 2f7f197

Browse files
VMSS | Resolved Conflict with Minimum Instances Configuration (#13)
Co-authored-by: natanelm <[email protected]>
1 parent 839b917 commit 2f7f197

File tree

6 files changed

+42
-6
lines changed

6 files changed

+42
-6
lines changed

modules/vmss_existing_vnet/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module "example_module" {
4949
availability_zones_num = "1"
5050
minimum_number_of_vm_instances = 2
5151
maximum_number_of_vm_instances = 10
52+
number_of_vm_instances = 2
5253
management_name = "mgmt"
5354
management_IP = "13.92.42.181"
5455
management_interface = "eth1-private"
@@ -108,6 +109,7 @@ module "example_module" {
108109
| **availability_zones_num** | A list of a single item of the Availability Zone which the Virtual Machine should be allocated in | string | "centralus", "eastus2", "francecentral", "northeurope", "southeastasia", "westeurope", "westus2", "eastus", "uksouth". |
109110
| **minimum_number_of_vm_instances** | The minimum number of VMSS instances for this resource | number | Valid values are in the range 0 - 10. |
110111
| **maximum_number_of_vm_instances** | The maximum number of VMSS instances for this resource | number | Valid values are in the range 0 - 10. |
112+
| **number_of_vm_instances** | The default number of VMSS instances to deploy. | number | The number of VMSS instances must not be less then `minimum_number_of_vm_instances`. If the number of VMSS is greater then the `maximum_number_of_vm_instances` use the maximum number as default.<br/>**Default**: 2; |
111113
| **management_name** | The name of the management server as it appears in the configuration file | string | Field cannot be empty. Only alphanumeric characters or '_'/'-' are allowed, and the name must be 1-30 characters long. |
112114
| **management_IP** | The IP address used to manage the VMSS instances | string | A valid IP address. |
113115
| **management_interface** | Management option for the Gateways in the VMSS | string | "eth0-public" - Manages the GWs using their external NIC's public IP address;<br/>"eth0-private" - Manages the GWs using their external NIC's private IP address;<br/>"eth1-private" - Manages the GWs using their internal NIC's private IP address.<br/>**Default:** "eth1-private" |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
locals {
22
module_name = "vmss_terraform_registry"
33
module_version = "1.0.5"
4+
5+
// Validate that the minimum number of VM instances is at least 0.
6+
// If not, return an error message.
7+
validate_number_of_vm_instances_range = var.minimum_number_of_vm_instances >= 0 && var.maximum_number_of_vm_instances >= 0 ? 0 : index("error: The minimum and maximum number of VM instances must be at least 0.")
8+
9+
// Validate that the maximum number of VM instances is greater than or equal to the minimum number of VM instances.
10+
// If not, return an error message.
11+
validate_maximum_number_of_vm_instances = var.maximum_number_of_vm_instances >= var.minimum_number_of_vm_instances ? 0 : index("error: The maximum number of VM instances must be greater than or equal to the minimum number of VM instances.")
12+
13+
// The number of VM instances should not exceed the maximum allowed.
14+
// If the provided number of instances exceeds the maximum, use the maximum instead.
15+
number_of_vm_instances = var.maximum_number_of_vm_instances >= var.number_of_vm_instances ? var.number_of_vm_instances : var.maximum_number_of_vm_instances
16+
17+
// Validate the number of VM instances against the minimum requirement.
18+
// If the number of instances is less than the minimum, return an error message.
19+
validate_number_of_vm_instances = local.number_of_vm_instances >= var.minimum_number_of_vm_instances? 0 : index("error: The number of VM instances must be at least ${var.minimum_number_of_vm_instances}.")
420
}

modules/vmss_existing_vnet/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module "common" {
77
installation_type = var.installation_type
88
module_name = local.module_name
99
module_version = local.module_version
10-
number_of_vm_instances = var.number_of_vm_instances
10+
number_of_vm_instances = local.number_of_vm_instances
1111
allow_upload_download = var.allow_upload_download
1212
vm_size = var.vm_size
1313
disk_size = var.disk_size
@@ -217,7 +217,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "vmss" {
217217
resource_group_name = module.common.resource_group_name
218218
sku = module.common.vm_size
219219
zones = local.availability_zones_num_condition
220-
instances = var.number_of_vm_instances
220+
instances = local.number_of_vm_instances
221221
overprovision = false
222222

223223
dynamic "identity" {

modules/vmss_new_vnet/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ module "example_module" {
5353
availability_zones_num = "1"
5454
minimum_number_of_vm_instances = 2
5555
maximum_number_of_vm_instances = 10
56+
number_of_vm_instances = 2
5657
management_name = "mgmt"
5758
management_IP = "13.92.42.181"
5859
management_interface = "eth1-private"
@@ -105,8 +106,9 @@ module "example_module" {
105106
| **allow_upload_download** | Automatically download Blade Contracts and other important data. Improve product experience by sending data to Check Point | boolean | true;<br />false;<br /> |
106107
| **authentication_type** | Specifies whether a password authentication or SSH Public Key authentication should be used | string | "Password";<br />"SSH Public Key";<br /> |
107108
| **availability_zones_num** | A list of a single item of the Availability Zone where the Virtual Machine should be allocated | string | "centralus", "eastus2", "francecentral", "northeurope", "southeastasia", "westeurope", "westus2", "eastus", "uksouth"<br /> |
108-
| **minimum_number_of_vm_instances** | The minimum number of VMSS instances for this resource | number | Valid values are in the range 0 - 10<br /> |
109-
| **maximum_number_of_vm_instances** | The maximum number of VMSS instances for this resource | number | Valid values are in the range 0 - 10<br /> |
109+
| **minimum_number_of_vm_instances** | The minimum number of VMSS instances for this resource. | number | Valid values are in the range 0 - 10<br /> |
110+
| **maximum_number_of_vm_instances** | The maximum number of VMSS instances for this resource. | number | Valid values are in the range 0 - 10<br /> |
111+
| **number_of_vm_instances** | The default number of VMSS instances to deploy. | number | The number of VMSS instances must not be less then `minimum_number_of_vm_instances`. If the number of VMSS is greater then the `maximum_number_of_vm_instances` use the maximum number by default.<br/>**Default**: 2; |
110112
| **management_name** | The name of the management server as it appears in the configuration file | string | Field cannot be empty. Only alphanumeric characters or '_'/'-' are allowed, and the name must be 1-30 characters long<br /> |
111113
| **management_IP** | The IP address used to manage the VMSS instances | string | A valid IP address<br /> |
112114
| **management_interface** | Management option for the Gateways in the VMSS | string | "eth0-public" - Manages the GWs using their external NIC's public IP address;<br />"eth0-private" - Manages the GWs using their external NIC's private IP address;<br />"eth1-private" - Manages the GWs using their internal NIC's private IP address;<br />**Default:** "eth1-private" |

modules/vmss_new_vnet/locals.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
locals {
22
module_name = "vmss_terraform_registry"
33
module_version = "1.0.5"
4+
5+
// Validate that the minimum number of VM instances is at least 0.
6+
// If not, return an error message.
7+
validate_number_of_vm_instances_range = var.minimum_number_of_vm_instances >= 0 && var.maximum_number_of_vm_instances >= 0 ? 0 : index("error: The minimum and maximum number of VM instances must be at least 0.")
8+
9+
// Validate that the maximum number of VM instances is greater than or equal to the minimum number of VM instances.
10+
// If not, return an error message.
11+
validate_maximum_number_of_vm_instances = var.maximum_number_of_vm_instances >= var.minimum_number_of_vm_instances ? 0 : index("error: The maximum number of VM instances must be greater than or equal to the minimum number of VM instances.")
12+
13+
// The number of VM instances should not exceed the maximum allowed.
14+
// If the provided number of instances exceeds the maximum, use the maximum instead.
15+
number_of_vm_instances = var.maximum_number_of_vm_instances >= var.number_of_vm_instances ? var.number_of_vm_instances : var.maximum_number_of_vm_instances
16+
17+
// Validate the number of VM instances against the minimum requirement.
18+
// If the number of instances is less than the minimum, return an error message.
19+
validate_number_of_vm_instances = local.number_of_vm_instances >= var.minimum_number_of_vm_instances? 0 : index("error: The number of VM instances must be at least ${var.minimum_number_of_vm_instances}.")
420
}

modules/vmss_new_vnet/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module "common" {
77
installation_type = var.installation_type
88
module_name = local.module_name
99
module_version = local.module_version
10-
number_of_vm_instances = var.number_of_vm_instances
10+
number_of_vm_instances = local.number_of_vm_instances
1111
allow_upload_download = var.allow_upload_download
1212
vm_size = var.vm_size
1313
disk_size = var.disk_size
@@ -213,7 +213,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "vmss" {
213213
resource_group_name = module.common.resource_group_name
214214
sku = module.common.vm_size
215215
zones = local.availability_zones_num_condition
216-
instances = var.number_of_vm_instances
216+
instances = local.number_of_vm_instances
217217
overprovision = false
218218

219219
dynamic "identity" {

0 commit comments

Comments
 (0)