Skip to content

Commit 2a04dde

Browse files
chkp-natanelmchkp-avivm
authored andcommitted
Enabled support for custom tags across all solutions
1 parent 35f8502 commit 2a04dde

File tree

50 files changed

+504
-285
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+504
-285
lines changed

modules/common/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
resource "azurerm_resource_group" "resource_group" {
22
name = var.resource_group_name
33
location = var.location
4+
tags = var.tags
45
}
56

modules/common/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ variable "maintenance_mode_password_hash" {
3737
}
3838

3939
variable "tags" {
40-
type = map(string)
41-
description = "A map of the tags to use on the resources that are deployed with this module."
40+
description = "Tags to be associated with the resource group."
41+
type = map(string)
4242
default = {}
4343
}
4444

modules/high_availability_existing_vnet/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ provider "azurerm" {
2323
module "example_module" {
2424
2525
source = "CheckPointSW/cloudguard-network-security/azure//modules/high_availability_existing_vnet"
26-
version = "1.0.5"
26+
version = "1.0.6"
2727
2828
tenant_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
2929
source_image_vhd_uri = "noCustomUri"
@@ -128,3 +128,4 @@ module "example_module" {
128128
| **storage_account_additional_ips** | IPs/CIDRs that are allowed access to the Storage Account | list(string) | A list of valid IPs and CIDRs<br />**Default:** [] |
129129
| **security_rules** | Security rules for the Network Security Group | list(any) | A security rule composed of: {name, priority, direction, access, protocol, source_port_ranges, destination_port_ranges, source_address_prefix, destination_address_prefix, description}<br />**Default:** [] |
130130
| **admin_SSH_key** | The SSH public key for SSH connections to the instance. Used when the authentication_type is 'SSH Public Key' | string | **Default:** "" |
131+
| **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"}}.<br/>Supported resource types for tag assignment include:<br>`all` (Applies tags universally to all resource instances)<br/>`resource-group`<br/>`network-interface`<br/>`public-ip`<br/>`public-ip-prefix`<br/>`load-balancer`<br/>`storage-account`<br/>`virtual-machine`<br/>`custom-image`<br/>`availability-set`<br/>**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)) | {} |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
locals {
22
module_name = "ha_terraform"
3-
module_version = "1.0.5"
3+
module_version = "1.0.6"
44
}

modules/high_availability_existing_vnet/main.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module "common" {
1919
serial_console_password_hash = var.serial_console_password_hash
2020
maintenance_mode_password_hash = var.maintenance_mode_password_hash
2121
storage_account_additional_ips = var.storage_account_additional_ips
22+
tags = merge(lookup(var.tags, "resource-group", {}), lookup(var.tags, "all", {}))
2223
}
2324

2425
//********************** Networking **************************//
@@ -35,6 +36,7 @@ resource "azurerm_public_ip_prefix" "public_ip_prefix" {
3536
location = module.common.resource_group_location
3637
resource_group_name = module.common.resource_group_name
3738
prefix_length = 30
39+
tags = merge(lookup(var.tags, "public-ip-prefix", {}), lookup(var.tags, "all", {}))
3840
}
3941

4042
data "azurerm_subnet" "frontend" {
@@ -58,6 +60,7 @@ resource "azurerm_public_ip" "public-ip" {
5860
sku = var.sku
5961
domain_name_label = "${lower(var.cluster_name)}-${count.index+1}-${random_id.random_id.hex}"
6062
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
63+
tags = merge(lookup(var.tags, "public-ip", {}), lookup(var.tags, "all", {}))
6164
}
6265

6366
resource "azurerm_public_ip" "cluster-vip" {
@@ -68,6 +71,7 @@ resource "azurerm_public_ip" "cluster-vip" {
6871
sku = var.sku
6972
domain_name_label = "${lower(var.cluster_name)}-vip-${random_id.random_id.hex}"
7073
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
74+
tags = merge(lookup(var.tags, "public-ip", {}), lookup(var.tags, "all", {}))
7175
}
7276

7377
resource "azurerm_network_interface" "nic_vip" {
@@ -103,6 +107,8 @@ resource "azurerm_network_interface" "nic_vip" {
103107
ip_configuration
104108
]
105109
}
110+
111+
tags = merge(lookup(var.tags, "network-interface", {}), lookup(var.tags, "all", {}))
106112
}
107113

108114
resource "azurerm_network_interface_backend_address_pool_association" "nic_vip_lb_association" {
@@ -137,6 +143,8 @@ resource "azurerm_network_interface" "nic" {
137143
ip_configuration
138144
]
139145
}
146+
147+
tags = merge(lookup(var.tags, "network-interface", {}), lookup(var.tags, "all", {}))
140148
}
141149

142150
resource "azurerm_network_interface_backend_address_pool_association" "nic_lb_association" {
@@ -162,6 +170,8 @@ resource "azurerm_network_interface" "nic1" {
162170
private_ip_address_allocation = var.vnet_allocation_method
163171
private_ip_address = cidrhost(data.azurerm_subnet.backend.address_prefixes[0], var.backend_IP_addresses[count.index+1])
164172
}
173+
174+
tags = merge(lookup(var.tags, "network-interface", {}), lookup(var.tags, "all", {}))
165175
}
166176

167177
resource "azurerm_network_interface_backend_address_pool_association" "nic1_lb_association" {
@@ -181,6 +191,7 @@ resource "azurerm_public_ip" "public-ip-lb" {
181191
sku = var.sku
182192
domain_name_label = "${lower(var.cluster_name)}-${random_id.random_id.hex}"
183193
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
194+
tags = merge(lookup(var.tags, "public-ip", {}), lookup(var.tags, "all", {}))
184195
}
185196

186197
resource "azurerm_lb" "frontend-lb" {
@@ -195,6 +206,8 @@ resource "azurerm_lb" "frontend-lb" {
195206
name = "LoadBalancerFrontend"
196207
public_ip_address_id = azurerm_public_ip.public-ip-lb.id
197208
}
209+
210+
tags = merge(lookup(var.tags, "load-balancer", {}), lookup(var.tags, "all", {}))
198211
}
199212

200213
resource "azurerm_lb_backend_address_pool" "frontend-lb-pool" {
@@ -213,6 +226,8 @@ resource "azurerm_lb" "backend-lb" {
213226
private_ip_address_allocation = var.vnet_allocation_method
214227
private_ip_address = cidrhost(data.azurerm_subnet.backend.address_prefixes[0], var.backend_IP_addresses[0])
215228
}
229+
230+
tags = merge(lookup(var.tags, "load-balancer", {}), lookup(var.tags, "all", {}))
216231
}
217232

218233
resource "azurerm_lb_backend_address_pool" "backend-lb-pool" {
@@ -256,6 +271,7 @@ resource "azurerm_availability_set" "availability-set" {
256271
platform_fault_domain_count = 2
257272
platform_update_domain_count = 5
258273
managed = true
274+
tags = merge(lookup(var.tags, "availability-set", {}), lookup(var.tags, "all", {}))
259275
}
260276

261277
//********************** Storage accounts **************************//
@@ -283,6 +299,7 @@ resource "azurerm_storage_account" "vm-boot-diagnostics-storage" {
283299
days = "15"
284300
}
285301
}
302+
tags = merge(lookup(var.tags, "storage-account", {}), lookup(var.tags, "all", {}))
286303
}
287304

288305
//********************** Virtual Machines **************************//
@@ -301,6 +318,8 @@ resource "azurerm_image" "custom-image" {
301318
os_state = "Generalized"
302319
blob_uri = var.source_image_vhd_uri
303320
}
321+
322+
tags = merge(lookup(var.tags, "custom-image", {}), lookup(var.tags, "all", {}))
304323
}
305324
resource "azurerm_virtual_machine" "vm-instance-availability-set" {
306325
depends_on = [
@@ -393,6 +412,8 @@ resource "azurerm_virtual_machine" "vm-instance-availability-set" {
393412
enabled = module.common.boot_diagnostics
394413
storage_uri = module.common.boot_diagnostics ? join(",", azurerm_storage_account.vm-boot-diagnostics-storage.*.primary_blob_endpoint) : ""
395414
}
415+
416+
tags = merge(lookup(var.tags, "virtual-machine", {}), lookup(var.tags, "all", {}))
396417
}
397418

398419
resource "azurerm_virtual_machine" "vm-instance-availability-zone" {
@@ -487,6 +508,8 @@ resource "azurerm_virtual_machine" "vm-instance-availability-zone" {
487508
enabled = module.common.boot_diagnostics
488509
storage_uri = module.common.boot_diagnostics ? join(",", azurerm_storage_account.vm-boot-diagnostics-storage.*.primary_blob_endpoint) : ""
489510
}
511+
512+
tags = merge(lookup(var.tags, "virtual-machine", {}), lookup(var.tags, "all", {}))
490513
}
491514
//********************** Role Assigments **************************//
492515
data "azurerm_role_definition" "virtual_machine_contributor_role_definition" {

modules/high_availability_existing_vnet/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,8 @@ variable "security_rules" {
322322
default = []
323323
}
324324

325+
variable "tags" {
326+
description = "Assign tags by resource."
327+
type = map(map(string))
328+
default = {}
329+
}

modules/high_availability_new_vnet/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ provider "azurerm" {
2929
module "example_module" {
3030
3131
source = "CheckPointSW/cloudguard-network-security/azure//modules/high_availability_new_vnet"
32-
version = "1.0.5"
32+
version = "1.0.6"
3333
3434
tenant_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
3535
source_image_vhd_uri = "noCustomUri"
@@ -130,3 +130,4 @@ module "example_module" {
130130
| **storage_account_additional_ips**| IPs/CIDRs that are allowed access to the Storage Account | list(string) | A list of valid IPs and CIDRs<br />**Default:** [] |
131131
| **security_rules** | Security rules for the Network Security Group | list(any) | A security rule composed of: {name, priority, direction, access, protocol, source_port_ranges, destination_port_ranges, source_address_prefix, destination_address_prefix, description}<br />**Default:** [] |
132132
| **admin_SSH_key** | The SSH public key for SSH connections to the instance. Used when the authentication_type is 'SSH Public Key' | string | **Default:** "" |
133+
| **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"}}.<br/>Supported resource types for tag assignment include:<br>`all` (Applies tags universally to all resource instances)<br/>`resource-group`<br/>`virtual-network`<br/>`network-security-group`<br/>`network-interface`<br/>`public-ip`<br/>`public-ip-prefix`<br/>`load-balancer`<br/>`route-table`<br/>`storage-account`<br/>`virtual-machine`<br/>`custom-image`<br/>`availability-set`<br/>**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)) | {} |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
locals {
22
module_name = "ha_terraform"
3-
module_version = "1.0.5"
3+
module_version = "1.0.6"
44
}

modules/high_availability_new_vnet/main.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module "common" {
1919
serial_console_password_hash = var.serial_console_password_hash
2020
maintenance_mode_password_hash = var.maintenance_mode_password_hash
2121
storage_account_additional_ips = var.storage_account_additional_ips
22+
tags = merge(lookup(var.tags, "resource-group", {}), lookup(var.tags, "all", {}))
2223
}
2324

2425
//********************** Networking **************************//
@@ -30,6 +31,7 @@ module "vnet" {
3031
nsg_id = var.nsg_id == "" ? module.network_security_group[0].network_security_group_id: var.nsg_id
3132
address_space = var.address_space
3233
subnet_prefixes = var.subnet_prefixes
34+
tags = var.tags
3335
}
3436

3537
module "network_security_group" {
@@ -39,6 +41,7 @@ module "network_security_group" {
3941
security_group_name = "${module.common.resource_group_name}_nsg"
4042
location = module.common.resource_group_location
4143
security_rules = var.security_rules
44+
tags = merge(lookup(var.tags, "network-security-group", {}), lookup(var.tags, "all", {}))
4245
}
4346

4447
resource "random_id" "random_id" {
@@ -54,6 +57,7 @@ resource "azurerm_public_ip_prefix" "public_ip_prefix" {
5457
location = module.common.resource_group_location
5558
resource_group_name = module.common.resource_group_name
5659
prefix_length = 30
60+
tags = merge(lookup(var.tags, "public-ip-prefix", {}), lookup(var.tags, "all", {}))
5761
}
5862

5963
resource "azurerm_public_ip" "public-ip" {
@@ -65,6 +69,7 @@ resource "azurerm_public_ip" "public-ip" {
6569
sku = var.sku
6670
domain_name_label = "${lower(var.cluster_name)}-${count.index+1}-${random_id.random_id.hex}"
6771
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
72+
tags = merge(lookup(var.tags, "public-ip", {}), lookup(var.tags, "all", {}))
6873
}
6974

7075
resource "azurerm_public_ip" "cluster-vip" {
@@ -75,6 +80,7 @@ resource "azurerm_public_ip" "cluster-vip" {
7580
sku = var.sku
7681
domain_name_label = "${lower(var.cluster_name)}-vip-${random_id.random_id.hex}"
7782
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
83+
tags = merge(lookup(var.tags, "public-ip", {}), lookup(var.tags, "all", {}))
7884
}
7985

8086
resource "azurerm_network_interface" "nic_vip" {
@@ -110,6 +116,8 @@ resource "azurerm_network_interface" "nic_vip" {
110116
ip_configuration
111117
]
112118
}
119+
120+
tags = merge(lookup(var.tags, "network-interface", {}), lookup(var.tags, "all", {}))
113121
}
114122

115123
resource "azurerm_network_interface_backend_address_pool_association" "nic_vip_lb_association" {
@@ -144,6 +152,8 @@ resource "azurerm_network_interface" "nic" {
144152
ip_configuration
145153
]
146154
}
155+
156+
tags = merge(lookup(var.tags, "network-interface", {}), lookup(var.tags, "all", {}))
147157
}
148158

149159
resource "azurerm_network_interface_backend_address_pool_association" "nic_lb_association" {
@@ -169,6 +179,8 @@ resource "azurerm_network_interface" "nic1" {
169179
private_ip_address_allocation = module.vnet.allocation_method
170180
private_ip_address = cidrhost(module.vnet.subnet_prefixes[1], count.index+5)
171181
}
182+
183+
tags = merge(lookup(var.tags, "network-interface", {}), lookup(var.tags, "all", {}))
172184
}
173185

174186
resource "azurerm_network_interface_backend_address_pool_association" "nic1_lb_association" {
@@ -188,6 +200,7 @@ resource "azurerm_public_ip" "public-ip-lb" {
188200
sku = var.sku
189201
domain_name_label = "${lower(var.cluster_name)}-${random_id.random_id.hex}"
190202
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
203+
tags = merge(lookup(var.tags, "public-ip", {}), lookup(var.tags, "all", {}))
191204
}
192205

193206
resource "azurerm_lb" "frontend-lb" {
@@ -202,6 +215,8 @@ resource "azurerm_lb" "frontend-lb" {
202215
name = "LoadBalancerFrontend"
203216
public_ip_address_id = azurerm_public_ip.public-ip-lb.id
204217
}
218+
219+
tags = merge(lookup(var.tags, "load-balancer", {}), lookup(var.tags, "all", {}))
205220
}
206221

207222
resource "azurerm_lb_backend_address_pool" "frontend-lb-pool" {
@@ -220,6 +235,8 @@ resource "azurerm_lb" "backend-lb" {
220235
private_ip_address_allocation = module.vnet.allocation_method
221236
private_ip_address = cidrhost(module.vnet.subnet_prefixes[1], 4)
222237
}
238+
239+
tags = merge(lookup(var.tags, "load-balancer", {}), lookup(var.tags, "all", {}))
223240
}
224241

225242
resource "azurerm_lb_backend_address_pool" "backend-lb-pool" {
@@ -263,6 +280,8 @@ resource "azurerm_availability_set" "availability-set" {
263280
platform_fault_domain_count = 2
264281
platform_update_domain_count = 5
265282
managed = true
283+
284+
tags = merge(lookup(var.tags, "availability-set", {}), lookup(var.tags, "all", {}))
266285
}
267286

268287
//********************** Storage accounts **************************//
@@ -290,6 +309,7 @@ resource "azurerm_storage_account" "vm-boot-diagnostics-storage" {
290309
days = "15"
291310
}
292311
}
312+
tags = merge(lookup(var.tags, "storage-account", {}), lookup(var.tags, "all", {}))
293313
}
294314

295315
//********************** Virtual Machines **************************//
@@ -308,6 +328,8 @@ resource "azurerm_image" "custom-image" {
308328
os_state = "Generalized"
309329
blob_uri = var.source_image_vhd_uri
310330
}
331+
332+
tags = merge(lookup(var.tags, "custom-image", {}), lookup(var.tags, "all", {}))
311333
}
312334
resource "azurerm_virtual_machine" "vm-instance-availability-set" {
313335
depends_on = [
@@ -400,6 +422,8 @@ resource "azurerm_virtual_machine" "vm-instance-availability-set" {
400422
enabled = module.common.boot_diagnostics
401423
storage_uri = module.common.boot_diagnostics ? join(",", azurerm_storage_account.vm-boot-diagnostics-storage.*.primary_blob_endpoint) : ""
402424
}
425+
426+
tags = merge(lookup(var.tags, "virtual-machine", {}), lookup(var.tags, "all", {}))
403427
}
404428

405429
resource "azurerm_virtual_machine" "vm-instance-availability-zone" {
@@ -494,6 +518,8 @@ resource "azurerm_virtual_machine" "vm-instance-availability-zone" {
494518
enabled = module.common.boot_diagnostics
495519
storage_uri = module.common.boot_diagnostics ? join(",", azurerm_storage_account.vm-boot-diagnostics-storage.*.primary_blob_endpoint) : ""
496520
}
521+
522+
tags = merge(lookup(var.tags, "virtual-machine", {}), lookup(var.tags, "all", {}))
497523
}
498524
//********************** Role Assigments **************************//
499525
data "azurerm_role_definition" "virtual_machine_contributor_role_definition" {

modules/high_availability_new_vnet/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,9 @@ variable "security_rules" {
321321
}
322322
]
323323
}
324+
325+
variable "tags" {
326+
description = "Assign tags by resource."
327+
type = map(map(string))
328+
default = {}
329+
}

0 commit comments

Comments
 (0)