Skip to content

Commit 8b41f6e

Browse files
committed
feat(networksecurity): Add samples for intercept firewall rule creation
1 parent 9ff497b commit 8b41f6e

File tree

1 file changed

+78
-0
lines changed
  • network_security/intercept/basic/consumer

1 file changed

+78
-0
lines changed

network_security/intercept/basic/consumer/main.tf

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ resource "google_compute_network" "consumer_network" {
3131
}
3232
# [END networksecurity_intercept_create_consumer_network_tf]
3333

34+
# [START networksecurity_intercept_create_consumer_subnetwork_tf]
35+
resource "google_compute_subnetwork" "consumer_subnet" {
36+
provider = google-beta
37+
name = "consumer-subnet"
38+
region = "us-central1"
39+
ip_cidr_range = "10.10.0.0/16"
40+
network = google_compute_network.consumer_network.name
41+
}
42+
# [END networksecurity_intercept_create_consumer_subnetwork_tf]
43+
3444
# [START networksecurity_intercept_create_producer_deployment_group_tf]
3545
resource "google_network_security_intercept_deployment_group" "default" {
3646
provider = google-beta
@@ -58,4 +68,72 @@ resource "google_network_security_intercept_endpoint_group_association" "default
5868
intercept_endpoint_group = google_network_security_intercept_endpoint_group.default.id
5969
}
6070
# [END networksecurity_intercept_create_endpoint_group_association_tf]
71+
72+
73+
data "google_client_config" "default" {}
74+
75+
data "google_project" "default" {
76+
project_id = data.google_client_config.default.project
77+
}
78+
79+
data "google_organization" "default" {
80+
organization = data.google_project.default.org_id
81+
}
82+
83+
# [START networksecurity_intercept_create_security_profile_tf]
84+
resource "google_network_security_security_profile" "default" {
85+
provider = google-beta
86+
name = "security-profile"
87+
type = "CUSTOM_INTERCEPT"
88+
parent = "organizations/${data.google_organization.default.org_id}"
89+
location = "global"
90+
91+
custom_intercept_profile {
92+
intercept_endpoint_group = google_network_security_intercept_endpoint_group.default.id
93+
}
94+
}
95+
# [END networksecurity_intercept_create_security_profile_tf]
96+
97+
# [START networksecurity_intercept_create_security_profile_group_tf]
98+
resource "google_network_security_security_profile_group" "default" {
99+
provider = google-beta
100+
name = "security-profile-group"
101+
parent = "organizations/${data.google_organization.default.org_id}"
102+
custom_intercept_profile = google_network_security_security_profile.default.id
103+
}
104+
# [END networksecurity_intercept_create_security_profile_group_tf]
105+
106+
# [START networksecurity_intercept_create_firewall_policy_tf]
107+
resource "google_compute_network_firewall_policy" "default" {
108+
provider = google-beta
109+
name = "firewall-policy"
110+
}
111+
# [END networksecurity_intercept_create_firewall_policy_tf]
112+
113+
# [START networksecurity_intercept_create_firewall_policy_rule_tf]
114+
resource "google_compute_network_firewall_policy_rule" "default" {
115+
provider = google-beta
116+
firewall_policy = google_compute_network_firewall_policy.default.name
117+
priority = 1000
118+
action = "apply_security_profile_group"
119+
direction = "INGRESS"
120+
security_profile_group = "//networksecurity.googleapis.com/${google_network_security_security_profile_group.default.id}"
121+
122+
match {
123+
layer4_configs {
124+
ip_protocol = "tcp"
125+
ports = ["80"]
126+
}
127+
src_ip_ranges = ["10.10.0.0/16"]
128+
}
129+
}
130+
# [END networksecurity_intercept_create_firewall_policy_rule_tf]
131+
132+
# [START networksecurity_intercept_create_firewall_policy_association_tf]
133+
resource "google_compute_network_firewall_policy_association" "default" {
134+
name = "firewall-policy-assoc"
135+
attachment_target = google_compute_network.consumer_network.id
136+
firewall_policy = google_compute_network_firewall_policy.default.name
137+
}
138+
# [END networksecurity_intercept_create_firewall_policy_association_tf]
61139
# [END networksecurity_intercept_basic_consumer]

0 commit comments

Comments
 (0)