Skip to content

Commit 996b4f1

Browse files
authored
feat: Allow passing target_tags to configure the default firewall rules (#191)
fix typo use the doc generator instead of adding readme manually
1 parent da0def7 commit 996b4f1

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

modules/fabric-net-firewall/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ The resources created/managed by this module are:
2929

3030
- one optional ingress rule from internal CIDR ranges, only allowing ICMP by default
3131
- one optional ingress rule from admin CIDR ranges, allowing all protocols on all ports
32-
- one optional ingress rule for SSH on network tag `ssh`
33-
- one optional ingress rule for HTTP on network tag `http-server`
34-
- one optional ingress rule for HTTPS on network tag `https-server`
32+
- one optional ingress rule for SSH on network tag `ssh` by default
33+
- one optional ingress rule for HTTP on network tag `http-server` by default
34+
- one optional ingress rule for HTTPS on network tag `https-server` by default
3535
- one or more optional custom rules
3636

3737

@@ -46,6 +46,7 @@ module "net-firewall" {
4646
network = "my-vpc"
4747
internal_ranges_enabled = true
4848
internal_ranges = ["10.0.0.0/0"]
49+
internal_target_tags = ["internal"]
4950
custom_rules = {
5051
ingress-sample = {
5152
description = "Dummy sample ingress rule, tag-based."
@@ -76,13 +77,17 @@ module "net-firewall" {
7677
| admin\_ranges\_enabled | Enable admin ranges-based rules. | string | `"false"` | no |
7778
| custom\_rules | List of custom rule definitions (refer to variables file for syntax). | object | `<map>` | no |
7879
| http\_source\_ranges | List of IP CIDR ranges for tag-based HTTP rule, defaults to 0.0.0.0/0. | list | `<list>` | no |
80+
| http\_target\_tags | List of target tags for tag-based HTTP rule, defaults to http-server. | list | `<list>` | no |
7981
| https\_source\_ranges | List of IP CIDR ranges for tag-based HTTPS rule, defaults to 0.0.0.0/0. | list | `<list>` | no |
82+
| https\_target\_tags | List of target tags for tag-based HTTPS rule, defaults to https-server. | list | `<list>` | no |
8083
| internal\_allow | Allow rules for internal ranges. | list | `<list>` | no |
8184
| internal\_ranges | IP CIDR ranges for intra-VPC rules. | list | `<list>` | no |
8285
| internal\_ranges\_enabled | Create rules for intra-VPC ranges. | string | `"false"` | no |
86+
| internal\_target\_tags | List of target tags for intra-VPC rules. | list | `<list>` | no |
8387
| network | Name of the network this set of firewall rules applies to. | string | n/a | yes |
8488
| project\_id | Project id of the project that holds the network. | string | n/a | yes |
8589
| ssh\_source\_ranges | List of IP CIDR ranges for tag-based SSH rule, defaults to 0.0.0.0/0. | list | `<list>` | no |
90+
| ssh\_target\_tags | List of target tags for tag-based SSH rule, defaults to ssh. | list | `<list>` | no |
8691

8792
## Outputs
8893

modules/fabric-net-firewall/main.tf

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ resource "google_compute_firewall" "allow-internal" {
2525
network = var.network
2626
project = var.project_id
2727
source_ranges = var.internal_ranges
28+
target_tags = var.internal_target_tags
2829

2930
dynamic "allow" {
3031
for_each = [for rule in var.internal_allow :
@@ -38,13 +39,8 @@ resource "google_compute_firewall" "allow-internal" {
3839
ports = allow.value.ports
3940
}
4041
}
41-
4242
}
4343

44-
45-
46-
47-
4844
resource "google_compute_firewall" "allow-admins" {
4945
count = var.admin_ranges_enabled == true ? 1 : 0
5046
name = "${var.network}-ingress-admins"
@@ -77,7 +73,7 @@ resource "google_compute_firewall" "allow-tag-ssh" {
7773
network = var.network
7874
project = var.project_id
7975
source_ranges = var.ssh_source_ranges
80-
target_tags = ["ssh"]
76+
target_tags = var.ssh_target_tags
8177

8278
allow {
8379
protocol = "tcp"
@@ -92,7 +88,7 @@ resource "google_compute_firewall" "allow-tag-http" {
9288
network = var.network
9389
project = var.project_id
9490
source_ranges = var.http_source_ranges
95-
target_tags = ["http-server"]
91+
target_tags = var.http_target_tags
9692

9793
allow {
9894
protocol = "tcp"
@@ -107,7 +103,7 @@ resource "google_compute_firewall" "allow-tag-https" {
107103
network = var.network
108104
project = var.project_id
109105
source_ranges = var.https_source_ranges
110-
target_tags = ["https-server"]
106+
target_tags = var.https_target_tags
111107

112108
allow {
113109
protocol = "tcp"

modules/fabric-net-firewall/variables.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ variable "internal_ranges" {
3232
default = []
3333
}
3434

35+
variable "internal_target_tags" {
36+
description = "List of target tags for intra-VPC rules."
37+
default = []
38+
}
39+
3540
variable "internal_allow" {
3641
description = "Allow rules for internal ranges."
3742
default = [
@@ -56,16 +61,31 @@ variable "ssh_source_ranges" {
5661
default = ["0.0.0.0/0"]
5762
}
5863

64+
variable "ssh_target_tags" {
65+
description = "List of target tags for tag-based SSH rule, defaults to ssh."
66+
default = ["ssh"]
67+
}
68+
5969
variable "http_source_ranges" {
6070
description = "List of IP CIDR ranges for tag-based HTTP rule, defaults to 0.0.0.0/0."
6171
default = ["0.0.0.0/0"]
6272
}
6373

74+
variable "http_target_tags" {
75+
description = "List of target tags for tag-based HTTP rule, defaults to http-server."
76+
default = ["http-server"]
77+
}
78+
6479
variable "https_source_ranges" {
6580
description = "List of IP CIDR ranges for tag-based HTTPS rule, defaults to 0.0.0.0/0."
6681
default = ["0.0.0.0/0"]
6782
}
6883

84+
variable "https_target_tags" {
85+
description = "List of target tags for tag-based HTTPS rule, defaults to https-server."
86+
default = ["https-server"]
87+
}
88+
6989
variable "custom_rules" {
7090
description = "List of custom rule definitions (refer to variables file for syntax)."
7191
default = {}

0 commit comments

Comments
 (0)