Skip to content

Commit 2f44790

Browse files
authored
feat: Add support for enabling firewall logging on each rule (#236)
1 parent 11b4094 commit 2f44790

File tree

5 files changed

+68
-14
lines changed

5 files changed

+68
-14
lines changed

examples/submodule_firewall/main.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ locals {
7070
}]
7171

7272
extra_attributes = {
73-
disabled = true
74-
priority = 95
73+
disabled = true
74+
priority = 95
75+
flow_logs = true
76+
flow_logs_metadata = "EXCLUDE_ALL_METADATA"
7577
}
7678
}
7779

@@ -111,7 +113,8 @@ locals {
111113
}
112114
]
113115
extra_attributes = {
114-
priority = 30
116+
priority = 30
117+
flow_logs = true
115118
}
116119
}
117120
}

modules/fabric-net-firewall/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,20 @@ module "net-firewall" {
7373

7474
| Name | Description | Type | Default | Required |
7575
|------|-------------|------|---------|:--------:|
76-
| admin\_ranges | IP CIDR ranges that have complete access to all subnets. | `list` | `[]` | no |
76+
| admin\_ranges | IP CIDR ranges that have complete access to all subnets. | `list(string)` | `[]` | no |
7777
| admin\_ranges\_enabled | Enable admin ranges-based rules. | `bool` | `false` | no |
7878
| custom\_rules | List of custom rule definitions (refer to variables file for syntax). | <pre>map(object({<br> description = string<br> direction = string<br> action = string # (allow|deny)<br> ranges = list(string)<br> sources = list(string)<br> targets = list(string)<br> use_service_accounts = bool<br> rules = list(object({<br> protocol = string<br> ports = list(string)<br> }))<br> extra_attributes = map(string)<br> }))</pre> | `{}` | no |
79-
| http\_source\_ranges | List of IP CIDR ranges for tag-based HTTP rule, defaults to 0.0.0.0/0. | `list` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
79+
| http\_source\_ranges | List of IP CIDR ranges for tag-based HTTP rule, defaults to 0.0.0.0/0. | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
8080
| http\_target\_tags | List of target tags for tag-based HTTP rule, defaults to http-server. | `list` | <pre>[<br> "http-server"<br>]</pre> | no |
81-
| https\_source\_ranges | List of IP CIDR ranges for tag-based HTTPS rule, defaults to 0.0.0.0/0. | `list` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
82-
| https\_target\_tags | List of target tags for tag-based HTTPS rule, defaults to https-server. | `list` | <pre>[<br> "https-server"<br>]</pre> | no |
81+
| https\_source\_ranges | List of IP CIDR ranges for tag-based HTTPS rule, defaults to 0.0.0.0/0. | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
82+
| https\_target\_tags | List of target tags for tag-based HTTPS rule, defaults to https-server. | `list(string)` | <pre>[<br> "https-server"<br>]</pre> | no |
8383
| internal\_allow | Allow rules for internal ranges. | `list` | <pre>[<br> {<br> "protocol": "icmp"<br> }<br>]</pre> | no |
84-
| internal\_ranges | IP CIDR ranges for intra-VPC rules. | `list` | `[]` | no |
84+
| internal\_ranges | IP CIDR ranges for intra-VPC rules. | `list(string)` | `[]` | no |
8585
| internal\_ranges\_enabled | Create rules for intra-VPC ranges. | `bool` | `false` | no |
86-
| internal\_target\_tags | List of target tags for intra-VPC rules. | `list` | `[]` | no |
87-
| network | Name of the network this set of firewall rules applies to. | `any` | n/a | yes |
88-
| project\_id | Project id of the project that holds the network. | `any` | n/a | yes |
89-
| ssh\_source\_ranges | List of IP CIDR ranges for tag-based SSH rule, defaults to 0.0.0.0/0. | `list` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
86+
| internal\_target\_tags | List of target tags for intra-VPC rules. | `list(string)` | `[]` | no |
87+
| network | Name of the network this set of firewall rules applies to. | `string` | n/a | yes |
88+
| project\_id | Project id of the project that holds the network. | `string` | n/a | yes |
89+
| ssh\_source\_ranges | List of IP CIDR ranges for tag-based SSH rule, defaults to 0.0.0.0/0. | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
9090
| ssh\_target\_tags | List of target tags for tag-based SSH rule, defaults to ssh. | `list` | <pre>[<br> "ssh"<br>]</pre> | no |
9191

9292
## Outputs

modules/fabric-net-firewall/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ resource "google_compute_firewall" "custom" {
133133
priority = lookup(each.value.extra_attributes, "priority", 1000)
134134

135135
dynamic "log_config" {
136-
for_each = lookup(each.value, "flow_logs", false) ? [{
137-
metadata = lookup(each.value, "flow_logs_metadata", "INCLUDE_ALL_METADATA")
136+
for_each = lookup(each.value.extra_attributes, "flow_logs", false) ? [{
137+
metadata = lookup(each.value.extra_attributes, "flow_logs_metadata", "INCLUDE_ALL_METADATA")
138138
}] : []
139139
content {
140140
metadata = log_config.value.metadata

modules/fabric-net-firewall/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,29 @@
1616

1717
variable "network" {
1818
description = "Name of the network this set of firewall rules applies to."
19+
type = string
1920
}
2021

2122
variable "project_id" {
2223
description = "Project id of the project that holds the network."
24+
type = string
2325
}
2426

2527
variable "internal_ranges_enabled" {
2628
description = "Create rules for intra-VPC ranges."
29+
type = bool
2730
default = false
2831
}
2932

3033
variable "internal_ranges" {
3134
description = "IP CIDR ranges for intra-VPC rules."
35+
type = list(string)
3236
default = []
3337
}
3438

3539
variable "internal_target_tags" {
3640
description = "List of target tags for intra-VPC rules."
41+
type = list(string)
3742
default = []
3843
}
3944

@@ -48,16 +53,19 @@ variable "internal_allow" {
4853

4954
variable "admin_ranges_enabled" {
5055
description = "Enable admin ranges-based rules."
56+
type = bool
5157
default = false
5258
}
5359

5460
variable "admin_ranges" {
5561
description = "IP CIDR ranges that have complete access to all subnets."
62+
type = list(string)
5663
default = []
5764
}
5865

5966
variable "ssh_source_ranges" {
6067
description = "List of IP CIDR ranges for tag-based SSH rule, defaults to 0.0.0.0/0."
68+
type = list(string)
6169
default = ["0.0.0.0/0"]
6270
}
6371

@@ -68,6 +76,7 @@ variable "ssh_target_tags" {
6876

6977
variable "http_source_ranges" {
7078
description = "List of IP CIDR ranges for tag-based HTTP rule, defaults to 0.0.0.0/0."
79+
type = list(string)
7180
default = ["0.0.0.0/0"]
7281
}
7382

@@ -78,11 +87,13 @@ variable "http_target_tags" {
7887

7988
variable "https_source_ranges" {
8089
description = "List of IP CIDR ranges for tag-based HTTPS rule, defaults to 0.0.0.0/0."
90+
type = list(string)
8191
default = ["0.0.0.0/0"]
8292
}
8393

8494
variable "https_target_tags" {
8595
description = "List of target tags for tag-based HTTPS rule, defaults to https-server."
96+
type = list(string)
8697
default = ["https-server"]
8798
}
8899

test/integration/submodule_firewall/controls/gcloud.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@
8787
}
8888
)
8989
end
90+
91+
it "has logging disabled" do
92+
expect(data["logConfig"]).to include(
93+
{
94+
"enable" => false
95+
}
96+
)
97+
end
9098
end
9199
end
92100

@@ -132,6 +140,22 @@
132140
}
133141
)
134142
end
143+
144+
it "has logging enabled" do
145+
expect(data["logConfig"]).to include(
146+
{
147+
"enable" => true
148+
}
149+
)
150+
end
151+
152+
it "has expected logging metadata" do
153+
expect(data["logConfig"]).to include(
154+
{
155+
"metadata" => "EXCLUDE_ALL_METADATA"
156+
}
157+
)
158+
end
135159
end
136160
end
137161

@@ -178,6 +202,22 @@
178202
}
179203
)
180204
end
205+
206+
it "has logging enabled" do
207+
expect(data["logConfig"]).to include(
208+
{
209+
"enable" => true
210+
}
211+
)
212+
end
213+
214+
it "has expected logging metadata" do
215+
expect(data["logConfig"]).to include(
216+
{
217+
"metadata" => "INCLUDE_ALL_METADATA"
218+
}
219+
)
220+
end
181221
end
182222
end
183223

0 commit comments

Comments
 (0)