@@ -48,21 +48,96 @@ module "test-vpc-module" {
4848 ]
4949}
5050
51+ // Custom firewall rules
52+ locals {
53+ custom_rules = {
54+ // Example of custom tcp/udp rule
55+ deny-ingress-6534-6566 = {
56+ description = " Deny all INGRESS to port 6534-6566"
57+ direction = " INGRESS"
58+ action = " deny"
59+ ranges = [" 0.0.0.0/0" ] # source or destination ranges (depends on `direction`)
60+ use_service_accounts = false # if `true` targets/sources expect list of instances SA, if false - list of tags
61+ targets = null # target_service_accounts or target_tags depends on `use_service_accounts` value
62+ sources = null # source_service_accounts or source_tags depends on `use_service_accounts` value
63+ rules = [{
64+ protocol = " tcp"
65+ ports = [" 6534-6566" ]
66+ },
67+ {
68+ protocol = " udp"
69+ ports = [" 6534-6566" ]
70+ }]
71+
72+ extra_attributes = {
73+ disabled = true
74+ priority = 95
75+ }
76+ }
77+
78+ // Example how to allow connection from instances with `backend` tag, to instances with `databases` tag
79+ allow-backend-to-databases = {
80+ description = " Allow backend nodes connection to databases instances"
81+ direction = " INGRESS"
82+ action = " allow"
83+ ranges = null
84+ use_service_accounts = false
85+ targets = [" databases" ] # target_tags
86+ sources = [" backed" ] # source_tags
87+ rules = [{
88+ protocol = " tcp"
89+ ports = [" 3306" , " 5432" , " 1521" , " 1433" ]
90+ }]
91+
92+ extra_attributes = {}
93+ }
94+
95+ // Example how to allow connection from an instance with a given service account
96+ allow-all-admin-sa = {
97+ description = " Allow all traffic from admin sa instances"
98+ direction = " INGRESS"
99+ action = " allow"
100+ ranges = null
101+ use_service_accounts = true
102+ targets = null
103+ 104+ rules = [{
105+ protocol = " tcp"
106+ ports = null # all ports
107+ },
108+ {
109+ protocol = " udp"
110+ ports = null # all ports
111+ }
112+ ]
113+ extra_attributes = {
114+ priority = 30
115+ }
116+ }
117+ }
118+ }
119+
120+
121+
51122module "test-firewall-submodule" {
52123 source = " ../../modules/fabric-net-firewall"
53124 project_id = var. project_id
54125 network = module. test-vpc-module . network_name
55126 internal_ranges_enabled = true
56127 internal_ranges = module. test-vpc-module . subnets_ips
57128
58- internal_allow = [{
59- protocol = " icmp"
129+ internal_allow = [
130+ {
131+ protocol = " icmp"
60132 },
61133 {
62- protocol = " tcp"
134+ protocol = " tcp" ,
135+ ports = [" 8080" , " 1000-2000" ]
63136 },
64137 {
65138 protocol = " udp"
139+ # all ports will be opened if `ports` key isn't specified
66140 },
67141 ]
142+ custom_rules = local. custom_rules
68143}
0 commit comments