Refactor firewall policy module (#1576)
* refactor module interface * hierarchical attachment and example * hierarchical rules and TODO * split rules resources * additional fields * keep using a single resource for rules * factory * factory test * boilerplate * Prefix ingress and egress rule ids * Tests for other firewall policy types * Fix rule id and names --------- Co-authored-by: Julio Castillo <jccb@google.com>
This commit is contained in:
committed by
GitHub
parent
8917333bde
commit
80ada0e8dd
98
tests/modules/net_vpc_firewall_policy/examples/factory.yaml
Normal file
98
tests/modules/net_vpc_firewall_policy/examples/factory.yaml
Normal file
@@ -0,0 +1,98 @@
|
||||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
values:
|
||||
module.firewall-policy.google_compute_firewall_policy.hierarchical[0]:
|
||||
parent: folders/1234567890
|
||||
short_name: test-1
|
||||
module.firewall-policy.google_compute_firewall_policy_association.hierarchical["test"]:
|
||||
attachment_target: folders/4567890123
|
||||
name: test-1-test
|
||||
module.firewall-policy.google_compute_firewall_policy_rule.hierarchical["egress/icmp"]:
|
||||
action: allow
|
||||
direction: INGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges: null
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: icmp
|
||||
ports: null
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges:
|
||||
- 10.0.0.0/8
|
||||
src_region_codes: null
|
||||
src_threat_intelligences: null
|
||||
priority: 1000
|
||||
target_resources: null
|
||||
target_service_accounts: null
|
||||
module.firewall-policy.google_compute_firewall_policy_rule.hierarchical["ingress/smtp"]:
|
||||
action: deny
|
||||
direction: EGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges:
|
||||
- 10.0.0.0/8
|
||||
- 172.16.0.0/12
|
||||
- 192.168.0.0/24
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: tcp
|
||||
ports:
|
||||
- '25'
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges: null
|
||||
src_region_codes: null
|
||||
src_threat_intelligences: null
|
||||
priority: 900
|
||||
target_resources: null
|
||||
target_service_accounts: null
|
||||
module.firewall-policy.google_compute_firewall_policy_rule.hierarchical["ingress/ssh"]:
|
||||
action: allow
|
||||
direction: INGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges: null
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: tcp
|
||||
ports:
|
||||
- '22'
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges:
|
||||
- 10.0.0.0/8
|
||||
src_region_codes: null
|
||||
src_threat_intelligences: null
|
||||
priority: 1002
|
||||
target_resources: null
|
||||
target_service_accounts: null
|
||||
|
||||
counts:
|
||||
google_compute_firewall_policy: 1
|
||||
google_compute_firewall_policy_association: 1
|
||||
google_compute_firewall_policy_rule: 3
|
||||
137
tests/modules/net_vpc_firewall_policy/examples/global-net.yaml
Normal file
137
tests/modules/net_vpc_firewall_policy/examples/global-net.yaml
Normal file
@@ -0,0 +1,137 @@
|
||||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
values:
|
||||
module.firewall-policy.google_compute_network_firewall_policy.net-global[0]:
|
||||
name: test-1
|
||||
project: my-project
|
||||
module.firewall-policy.google_compute_network_firewall_policy_association.net-global["my-vpc"]:
|
||||
firewall_policy: test-1
|
||||
name: test-1-my-vpc
|
||||
project: my-project
|
||||
module.firewall-policy.google_compute_network_firewall_policy_rule.net-global["egress/smtp"]:
|
||||
action: deny
|
||||
direction: EGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
firewall_policy: test-1
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges:
|
||||
- 0.0.0.0/0
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: tcp
|
||||
ports:
|
||||
- '25'
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges: null
|
||||
src_region_codes: null
|
||||
src_secure_tags: []
|
||||
src_threat_intelligences: null
|
||||
priority: 900
|
||||
project: my-project
|
||||
rule_name: smtp
|
||||
target_secure_tags: []
|
||||
target_service_accounts: null
|
||||
module.firewall-policy.google_compute_network_firewall_policy_rule.net-global["ingress/icmp"]:
|
||||
action: allow
|
||||
direction: INGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
firewall_policy: test-1
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges: null
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: icmp
|
||||
ports: null
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges:
|
||||
- 0.0.0.0/0
|
||||
src_region_codes: null
|
||||
src_secure_tags: []
|
||||
src_threat_intelligences: null
|
||||
priority: 1000
|
||||
project: my-project
|
||||
rule_name: icmp
|
||||
target_secure_tags: []
|
||||
target_service_accounts: null
|
||||
module.firewall-policy.google_compute_network_firewall_policy_rule.net-global["ingress/mgmt"]:
|
||||
action: allow
|
||||
direction: INGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
firewall_policy: test-1
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges: null
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: all
|
||||
ports: null
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges:
|
||||
- 10.1.1.0/24
|
||||
src_region_codes: null
|
||||
src_secure_tags: []
|
||||
src_threat_intelligences: null
|
||||
priority: 1001
|
||||
project: my-project
|
||||
rule_name: mgmt
|
||||
target_secure_tags: []
|
||||
target_service_accounts: null
|
||||
module.firewall-policy.google_compute_network_firewall_policy_rule.net-global["ingress/ssh"]:
|
||||
action: allow
|
||||
direction: INGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
firewall_policy: test-1
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges: null
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: tcp
|
||||
ports:
|
||||
- '22'
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges:
|
||||
- 10.0.0.0/8
|
||||
src_region_codes: null
|
||||
src_secure_tags: []
|
||||
src_threat_intelligences: null
|
||||
priority: 1002
|
||||
project: my-project
|
||||
rule_name: ssh
|
||||
target_secure_tags: []
|
||||
target_service_accounts: null
|
||||
|
||||
counts:
|
||||
google_compute_network_firewall_policy: 1
|
||||
google_compute_network_firewall_policy_association: 1
|
||||
google_compute_network_firewall_policy_rule: 4
|
||||
125
tests/modules/net_vpc_firewall_policy/examples/hierarchical.yaml
Normal file
125
tests/modules/net_vpc_firewall_policy/examples/hierarchical.yaml
Normal file
@@ -0,0 +1,125 @@
|
||||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
values:
|
||||
module.firewall-policy.google_compute_firewall_policy.hierarchical[0]:
|
||||
description: null
|
||||
parent: folders/1234567890
|
||||
short_name: test-1
|
||||
module.firewall-policy.google_compute_firewall_policy_association.hierarchical["test"]:
|
||||
attachment_target: folders/4567890123
|
||||
name: test-1-test
|
||||
module.firewall-policy.google_compute_firewall_policy_rule.hierarchical["egress/smtp"]:
|
||||
action: deny
|
||||
description: null
|
||||
direction: EGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges:
|
||||
- 0.0.0.0/0
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: tcp
|
||||
ports:
|
||||
- '25'
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges: null
|
||||
src_region_codes: null
|
||||
src_threat_intelligences: null
|
||||
priority: 900
|
||||
target_resources: null
|
||||
target_service_accounts: null
|
||||
module.firewall-policy.google_compute_firewall_policy_rule.hierarchical["ingress/icmp"]:
|
||||
action: allow
|
||||
description: null
|
||||
direction: INGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges: null
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: icmp
|
||||
ports: null
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges:
|
||||
- 0.0.0.0/0
|
||||
src_region_codes: null
|
||||
src_threat_intelligences: null
|
||||
priority: 1000
|
||||
target_resources: null
|
||||
target_service_accounts: null
|
||||
module.firewall-policy.google_compute_firewall_policy_rule.hierarchical["ingress/mgmt"]:
|
||||
action: allow
|
||||
description: null
|
||||
direction: INGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges: null
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: all
|
||||
ports: null
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges:
|
||||
- 10.1.1.0/24
|
||||
src_region_codes: null
|
||||
src_threat_intelligences: null
|
||||
priority: 1001
|
||||
target_resources: null
|
||||
target_service_accounts: null
|
||||
module.firewall-policy.google_compute_firewall_policy_rule.hierarchical["ingress/ssh"]:
|
||||
action: allow
|
||||
description: null
|
||||
direction: INGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges: null
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: tcp
|
||||
ports:
|
||||
- '22'
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges:
|
||||
- 10.0.0.0/8
|
||||
src_region_codes: null
|
||||
src_threat_intelligences: null
|
||||
priority: 1002
|
||||
target_resources: null
|
||||
target_service_accounts: null
|
||||
|
||||
counts:
|
||||
google_compute_firewall_policy: 1
|
||||
google_compute_firewall_policy_association: 1
|
||||
google_compute_firewall_policy_rule: 4
|
||||
@@ -0,0 +1,86 @@
|
||||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
values:
|
||||
module.firewall-policy.google_compute_region_network_firewall_policy.net-regional[0]:
|
||||
name: test-1
|
||||
project: my-project
|
||||
region: europe-west8
|
||||
module.firewall-policy.google_compute_region_network_firewall_policy_association.net-regional["my-vpc"]:
|
||||
firewall_policy: test-1
|
||||
name: test-1-my-vpc
|
||||
project: my-project
|
||||
region: europe-west8
|
||||
module.firewall-policy.google_compute_region_network_firewall_policy_rule.net-regional["egress/smtp"]:
|
||||
action: deny
|
||||
direction: EGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
firewall_policy: test-1
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges:
|
||||
- 0.0.0.0/0
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: tcp
|
||||
ports:
|
||||
- '25'
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges: null
|
||||
src_region_codes: null
|
||||
src_secure_tags: []
|
||||
src_threat_intelligences: null
|
||||
priority: 900
|
||||
project: my-project
|
||||
region: europe-west8
|
||||
rule_name: smtp
|
||||
target_secure_tags: []
|
||||
target_service_accounts: null
|
||||
module.firewall-policy.google_compute_region_network_firewall_policy_rule.net-regional["ingress/icmp"]:
|
||||
action: allow
|
||||
direction: INGRESS
|
||||
disabled: false
|
||||
enable_logging: null
|
||||
firewall_policy: test-1
|
||||
match:
|
||||
- dest_address_groups: null
|
||||
dest_fqdns: null
|
||||
dest_ip_ranges: null
|
||||
dest_region_codes: null
|
||||
dest_threat_intelligences: null
|
||||
layer4_configs:
|
||||
- ip_protocol: icmp
|
||||
ports: null
|
||||
src_address_groups: null
|
||||
src_fqdns: null
|
||||
src_ip_ranges:
|
||||
- 0.0.0.0/0
|
||||
src_region_codes: null
|
||||
src_secure_tags: []
|
||||
src_threat_intelligences: null
|
||||
priority: 1000
|
||||
project: my-project
|
||||
region: europe-west8
|
||||
rule_name: icmp
|
||||
target_secure_tags: []
|
||||
target_service_accounts: null
|
||||
|
||||
counts:
|
||||
google_compute_region_network_firewall_policy: 1
|
||||
google_compute_region_network_firewall_policy_association: 1
|
||||
google_compute_region_network_firewall_policy_rule: 2
|
||||
Reference in New Issue
Block a user