From 22f0e2b90672b595155e811795c6adad65320f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Neme=C4=8Dkay?= <47064326+Dongalis@users.noreply.github.com> Date: Wed, 4 Feb 2026 08:56:46 +0100 Subject: [PATCH] Adding resource_group_create boolean variable to control if existing resource_group should be used or new one should be created --- CHANGELOG.md | 3 +++ modules/common/common/locals.tf | 5 +++++ modules/common/common/main.tf | 6 ++++++ modules/common/common/outputs.tf | 8 ++++---- modules/common/common/variables.tf | 13 +++++++++++++ modules/high-availability/README.md | 1 + modules/high-availability/main.tf | 1 + modules/high-availability/variables.tf | 6 ++++++ modules/management/README.md | 1 + modules/management/main.tf | 1 + modules/management/variables.tf | 6 ++++++ modules/mds/README.md | 1 + modules/mds/main.tf | 1 + modules/mds/variables.tf | 6 ++++++ modules/single-gateway/README.md | 1 + modules/single-gateway/main.tf | 1 + modules/single-gateway/variables.tf | 6 ++++++ modules/vmss/README.md | 1 + modules/vmss/main.tf | 1 + modules/vmss/variables.tf | 6 ++++++ 20 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 modules/common/common/locals.tf diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..73dd888 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changes made to CheckpointSW repo forked on 2026-02-04 + +- allow use of existing resource group in `common`, `high-availability`, `managment`, `mds`, `single-gateway` and `vmss` modules. Default behaviour is not changed diff --git a/modules/common/common/locals.tf b/modules/common/common/locals.tf new file mode 100644 index 0000000..a9b59df --- /dev/null +++ b/modules/common/common/locals.tf @@ -0,0 +1,5 @@ +locals { + resource_group = var.resource_group_create + ? azurerm_resource_group.resource_group[0] + : data.azurerm_resource_group.resource_group[0] +} diff --git a/modules/common/common/main.tf b/modules/common/common/main.tf index ec9d49d..8f99268 100644 --- a/modules/common/common/main.tf +++ b/modules/common/common/main.tf @@ -1,9 +1,15 @@ resource "azurerm_resource_group" "resource_group" { + count = var.resource_group_create ? 1 : 0 name = var.resource_group_name location = var.location tags = var.tags } +data "azurerm_resource_group" "existing_resource_group" { + count = var.resource_group_create ? 0 : 1 + name = var.resource_group_name +} + module "regions" { source = "Azure/avm-utl-regions/azurerm" version = "0.5.1" diff --git a/modules/common/common/outputs.tf b/modules/common/common/outputs.tf index 58879c3..4558683 100644 --- a/modules/common/common/outputs.tf +++ b/modules/common/common/outputs.tf @@ -1,17 +1,17 @@ output "resource_group_name" { - value = azurerm_resource_group.resource_group.name + value = local.resource_group.name } output "resource_group_id" { - value = azurerm_resource_group.resource_group.id + value = local.resource_group.id } output "resource_group_location" { - value = azurerm_resource_group.resource_group.location + value = local.resource_group.location } output "azurerm_resource_group_id" { - value = azurerm_resource_group.resource_group.id + value = local.resource_group.id } output "admin_username" { diff --git a/modules/common/common/variables.tf b/modules/common/common/variables.tf index 23769cb..70e7413 100644 --- a/modules/common/common/variables.tf +++ b/modules/common/common/variables.tf @@ -4,12 +4,25 @@ variable "resource_group_name" { type = string } +variable "existing_resource_group_name" { + description = "Azure Resource Group name to use if using an existing resource group; empty string creates resource_group_name rg" + type = string + default = "" + +} + variable "resource_group_id" { description = "Azure Resource Group ID to use." type = string default = "" } +variable "resource_group_create" { + description = "Define if Azure Resource Group should be created" + type = bool + default = true +} + variable "location" { description = "The location/region where resources will be created. The full list of Azure regions can be found at https://azure.microsoft.com/regions" type = string diff --git a/modules/high-availability/README.md b/modules/high-availability/README.md index a356994..b4ed798 100644 --- a/modules/high-availability/README.md +++ b/modules/high-availability/README.md @@ -160,6 +160,7 @@ Usage: `storage_account_deployment_mode = "None"`
| **subscription_id** | The subscription ID is used to pay for Azure cloud services | string | N/A | | **tenant_id** | The tenant ID of the Service Principal used to deploy the solution. | string | N/A | | **resource_group_name** | The name of the resource group that will contain the contents of the deployment. | string | Resource group names only allow alphanumeric characters, periods, underscores, hyphens, and parentheses and cannot end in a period. | +| **resource_group_create** | Define if Azure Resource Group should be created | boolean | true;
false;
**Default:** true | | **cluster_name** | The name of the Check Point Cluster Object. | string | Only alphanumeric characters are allowed, and the name must be 1-30 characters long. | | **location** | The region where the resources will be deployed at. | string | The full list of Azure regions can be found at https://azure.microsoft.com/regions. | | **tags** | Tags can be associated either globally across all resources or scoped to specific resource types. For example, a global tag can be defined as: {"all": {"example": "example"}}.
Supported resource types for tag assignment include:
`all` (Applies tags universally to all resource instances)
`resource-group`
`virtual-network`
`network-security-group`
`network-interface`
`public-ip`
`public-ip-prefix`
`load-balancer`
`route-table`
`storage-account`
`virtual-machine`
`custom-image`
`availability-set`
**Important:** When identical tag keys are defined both globally under `all` and within a specific resource scope, the tag value specified under `all` overrides the resource-specific tag. | map(map(string)) | **Defaults:** {} | diff --git a/modules/high-availability/main.tf b/modules/high-availability/main.tf index 260460d..67d2e1a 100644 --- a/modules/high-availability/main.tf +++ b/modules/high-availability/main.tf @@ -2,6 +2,7 @@ module "common" { source = "../common/common" resource_group_name = var.resource_group_name + resource_group_create = var.resource_group_create location = var.location is_zonal = var.availability_type == "Availability Zone" availability_zones_num = tostring(length(var.availability_zones)) diff --git a/modules/high-availability/variables.tf b/modules/high-availability/variables.tf index dfecbc7..1e88ca9 100644 --- a/modules/high-availability/variables.tf +++ b/modules/high-availability/variables.tf @@ -24,6 +24,12 @@ variable "resource_group_name" { type = string } +variable "resource_group_create" { + description = "Define if Azure Resource Group should be created" + type = bool + default = true +} + variable "cluster_name" { description = "Cluster name." type = string diff --git a/modules/management/README.md b/modules/management/README.md index f2177ac..7f771e5 100644 --- a/modules/management/README.md +++ b/modules/management/README.md @@ -117,6 +117,7 @@ Usage: `storage_account_deployment_mode = "None"`
| **tenant_id** | The tenant ID of the Service Principal used to deploy the solution | string | N/A | | **subscription_id** | The subscription ID is used to pay for Azure cloud services | string | N/A | | **resource_group_name** | The name of the resource group that will contain the contents of the deployment. | string | Resource group names only allow alphanumeric characters, periods, underscores, hyphens, and parenthesis and cannot end in a period. | +| **resource_group_create** | Define if Azure Resource Group should be created | boolean | true;
false;
**Default:** true | | **mgmt_name** | Management name | string. | N/A | | **location** | The region where the resources will be deployed. | string | The full list of Azure regions can be found at https://azure.microsoft.com/regions. | | **tags** | Tags can be associated either globally across all resources or scoped to specific resource types. For example, a global tag can be defined as: {"all": {"example": "example"}}.
Supported resource types for tag assignment include:
`all` (Applies tags universally to all resource instances)
`resource-group`
`virtual-network`
`network-security-group`
`network-interface`
`public-ip`
`route-table`
`storage-account`
`virtual-machine`
`custom-image`
**Important:** When identical tag keys are defined both globally under `all` and within a specific resource scope, the tag value specified under `all` overrides the resource-specific tag. | map(map(string)) | **Defaults:** {} | diff --git a/modules/management/main.tf b/modules/management/main.tf index 6ff13e5..9e7b3b3 100644 --- a/modules/management/main.tf +++ b/modules/management/main.tf @@ -2,6 +2,7 @@ module "common" { source = "../common/common" resource_group_name = var.resource_group_name + resource_group_create = var.resource_group_create location = var.location is_zonal = var.zone != "" availability_zones_num = "1" diff --git a/modules/management/variables.tf b/modules/management/variables.tf index 9fcd55a..07c5ad7 100644 --- a/modules/management/variables.tf +++ b/modules/management/variables.tf @@ -24,6 +24,12 @@ variable "resource_group_name" { type = string } +variable "resource_group_create" { + description = "Define if Azure Resource Group should be created" + type = bool + default = true +} + variable "mgmt_name" { description = "Management name." type = string diff --git a/modules/mds/README.md b/modules/mds/README.md index d8c3c4d..b32c2e1 100644 --- a/modules/mds/README.md +++ b/modules/mds/README.md @@ -122,6 +122,7 @@ Usage: `storage_account_deployment_mode = "None"`
| **tenant_id** | The tenant ID of the Service Principal used to deploy the solution | string | N/A | | **subscription_id** | The subscription ID is used to pay for Azure cloud services | string | N/A | | **resource_group_name** | The name of the resource group that will contain the contents of the deployment. | string | Resource group names only allow alphanumeric characters, periods, underscores, hyphens and parenthesis and cannot end in a period. | +| **resource_group_create** | Define if Azure Resource Group should be created | boolean | true;
false;
**Default:** true | | **mds_name** | MDS name. | string | N/A | | **location** | The region where the resources will be deployed at. | string | The full list of Azure regions can be found at https://azure.microsoft.com/regions. | | **tags** | Tags can be associated either globally across all resources or scoped to specific resource types. For example, a global tag can be defined as: {"all": {"example": "example"}}.
Supported resource types for tag assignment include:
`all` (Applies tags universally to all resource instances)
`resource-group`
`virtual-network`
`network-security-group`
`network-interface`
`public-ip`
`route-table`
`storage-account`
`virtual-machine`
`custom-image`
**Important:** When identical tag keys are defined both globally under `all` and within a specific resource scope, the tag value specified under `all` overrides the resource-specific tag. | map(map(string)) | **Default:** {} | diff --git a/modules/mds/main.tf b/modules/mds/main.tf index 5c3b9eb..11ddf1e 100644 --- a/modules/mds/main.tf +++ b/modules/mds/main.tf @@ -2,6 +2,7 @@ module "common" { source = "../common/common" resource_group_name = var.resource_group_name + resource_group_create = var.resource_group_create location = var.location is_zonal = var.zone != "" availability_zones_num = "1" diff --git a/modules/mds/variables.tf b/modules/mds/variables.tf index 79fc678..39eea01 100644 --- a/modules/mds/variables.tf +++ b/modules/mds/variables.tf @@ -24,6 +24,12 @@ variable "resource_group_name" { type = string } +variable "resource_group_create" { + description = "Define if Azure Resource Group should be created" + type = bool + default = true +} + variable "mds_name" { description = "MDS name." type = string diff --git a/modules/single-gateway/README.md b/modules/single-gateway/README.md index 2301125..29d902c 100644 --- a/modules/single-gateway/README.md +++ b/modules/single-gateway/README.md @@ -122,6 +122,7 @@ Usage: `storage_account_deployment_mode = "None"`
| **tenant_id** | The tenant ID of the Service Principal used to deploy the solution | string | N/A | | **subscription_id** | The subscription ID is used to pay for Azure cloud services | string | N/A | | **resource_group_name** | The name of the resource group that will contain the contents of the deployment. | string | Resource group names only allow alphanumeric characters, periods, underscores, hyphens and parenthesis and cannot end in a period. | +| **resource_group_create** | Define if Azure Resource Group should be created | boolean | true;
false;
**Default:** true | | **single_gateway_name** | The name of the Check Point single GW Object. | string | Only alphanumeric characters are allowed, and the name must be 1-30 characters long. | | **location** | The region where the resources will be deployed at. | string | The full list of Azure regions can be found at https://azure.microsoft.com/regions. | | **tags** | Tags can be associated either globally across all resources or scoped to specific resource types. For example, a global tag can be defined as: {"all": {"example": "example"}}.
Supported resource types for tag assignment include:
`all` (Applies tags universally to all resource instances)
`resource-group`
`virtual-network`
`network-security-group`
`network-interface`
`public-ip`
`route-table`
`storage-account`
`virtual-machine`
`custom-image`
**Important:** When identical tag keys are defined both globally under `all` and within a specific resource scope, the tag value specified under `all` overrides the resource-specific tag. | map(map(string)) | **Default:** {} | diff --git a/modules/single-gateway/main.tf b/modules/single-gateway/main.tf index d7e16c3..b904ded 100644 --- a/modules/single-gateway/main.tf +++ b/modules/single-gateway/main.tf @@ -2,6 +2,7 @@ module "common" { source = "../common/common" resource_group_name = var.resource_group_name + resource_group_create = var.resource_group_create location = var.location is_zonal = var.zone != "" availability_zones_num = "1" diff --git a/modules/single-gateway/variables.tf b/modules/single-gateway/variables.tf index d4a8958..557de9a 100644 --- a/modules/single-gateway/variables.tf +++ b/modules/single-gateway/variables.tf @@ -24,6 +24,12 @@ variable "resource_group_name" { type = string } +variable "resource_group_create" { + description = "Define if Azure Resource Group should be created" + type = bool + default = true +} + variable "single_gateway_name" { description = "Single Gateway name." type = string diff --git a/modules/vmss/README.md b/modules/vmss/README.md index ddb28e6..3908bfb 100644 --- a/modules/vmss/README.md +++ b/modules/vmss/README.md @@ -170,6 +170,7 @@ For more information, refer to the official - [Checkout the Azure Terraform docu | **tenant_id** | The tenant ID of the Service Principal used to deploy the solution | string | N/A | | **subscription_id** | The subscription ID is used to pay for Azure cloud services | string | N/A | | **resource_group_name** | The name of the resource group that will contain the contents of the deployment. | string | Resource group names only allow alphanumeric characters, periods, underscores, hyphens and parenthesis and cannot end in a period.
Note: Resource group name must not contain reserved words based on: sk40179. | +| **resource_group_create** | Define if Azure Resource Group should be created | boolean | true;
false;
**Default:** true | | **vmss_name** | The name of the Check Point VMSS Object. | string | Only alphanumeric characters are allowed, and the name must be 1-30 characters long.
Note: VMSS name must not contain reserved words based on: sk40179. | | **location** | The region where the resources will be deployed at. | string | The full list of Azure regions can be found at https://azure.microsoft.com/regions. | | **tags** | Tags can be associated either globally across all resources or scoped to specific resource types. For example, a global tag can be defined as: {"all": {"example": "example"}}.
Supported resource types for tag assignment include:
`all` (Applies tags universally to all resource instances)
`resource-group`
`virtual-network`
`network-security-group`
`network-interface`
`public-ip`
`public-ip-prefix`
`load-balancer`
`route-table`
`storage-account`
`virtual-machine-scale-set`
`custom-image`
`autoscale-setting`
**Important:** When identical tag keys are defined both globally under `all` and within a specific resource scope, the tag value specified under `all` overrides the resource-specific tag. | map(map(string)) | **Default:** {} | diff --git a/modules/vmss/main.tf b/modules/vmss/main.tf index 60c3f7d..16655c5 100644 --- a/modules/vmss/main.tf +++ b/modules/vmss/main.tf @@ -2,6 +2,7 @@ module "common" { source = "../common/common" resource_group_name = var.resource_group_name + resource_group_create = var.resource_group_create location = var.location is_zonal = var.availability_zones_num != "0" availability_zones_num = var.availability_zones_num diff --git a/modules/vmss/variables.tf b/modules/vmss/variables.tf index 20a3171..bafb055 100644 --- a/modules/vmss/variables.tf +++ b/modules/vmss/variables.tf @@ -24,6 +24,12 @@ variable "resource_group_name" { type = string } +variable "resource_group_create" { + description = "Define if Azure Resource Group should be created" + type = bool + default = true +} + variable "vmss_name" { description = "VMSS name." type = string