Skip to content

Commit 74fe876

Browse files
duvniglasnt
andauthored
feat(networksecurity): Add samples for intercept firewall rule creation (#835)
* feat(networksecurity): Add samples for intercept firewall rule creation * feat(networksecurity): Add samples for intercept firewall rule creation * Skip consumer test. --------- Co-authored-by: Katie McLaughlin <[email protected]>
1 parent 979dbe3 commit 74fe876

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

network_security/intercept/basic/consumer/main.tf

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414
* limitations under the License.
1515
*/
1616

17+
data "google_project" "default" {
18+
provider = google-beta
19+
}
20+
21+
# In case the project is in a folder, extract the organization ID from it.
22+
data "google_folder" "default" {
23+
provider = google-beta
24+
count = data.google_project.default.folder_id != "" ? 1 : 0
25+
folder = data.google_project.default.folder_id
26+
lookup_organization = true
27+
}
28+
29+
data "google_organization" "default" {
30+
provider = google-beta
31+
organization = data.google_project.default.org_id != "" ? data.google_project.default.org_id : data.google_folder.default[0].organization
32+
}
33+
1734
# [START networksecurity_intercept_basic_consumer]
1835
# [START networksecurity_intercept_create_producer_network_tf]
1936
resource "google_compute_network" "producer_network" {
@@ -31,6 +48,16 @@ resource "google_compute_network" "consumer_network" {
3148
}
3249
# [END networksecurity_intercept_create_consumer_network_tf]
3350

51+
# [START networksecurity_intercept_create_consumer_subnetwork_tf]
52+
resource "google_compute_subnetwork" "consumer_subnet" {
53+
provider = google-beta
54+
name = "consumer-subnet"
55+
region = "us-central1"
56+
ip_cidr_range = "10.10.0.0/16"
57+
network = google_compute_network.consumer_network.name
58+
}
59+
# [END networksecurity_intercept_create_consumer_subnetwork_tf]
60+
3461
# [START networksecurity_intercept_create_producer_deployment_group_tf]
3562
resource "google_network_security_intercept_deployment_group" "default" {
3663
provider = google-beta
@@ -58,4 +85,63 @@ resource "google_network_security_intercept_endpoint_group_association" "default
5885
intercept_endpoint_group = google_network_security_intercept_endpoint_group.default.id
5986
}
6087
# [END networksecurity_intercept_create_endpoint_group_association_tf]
88+
89+
# [START networksecurity_intercept_create_security_profile_tf]
90+
resource "google_network_security_security_profile" "default" {
91+
provider = google-beta
92+
name = "security-profile"
93+
type = "CUSTOM_INTERCEPT"
94+
parent = "organizations/${data.google_organization.default.org_id}"
95+
location = "global"
96+
97+
custom_intercept_profile {
98+
intercept_endpoint_group = google_network_security_intercept_endpoint_group.default.id
99+
}
100+
}
101+
# [END networksecurity_intercept_create_security_profile_tf]
102+
103+
# [START networksecurity_intercept_create_security_profile_group_tf]
104+
resource "google_network_security_security_profile_group" "default" {
105+
provider = google-beta
106+
name = "security-profile-group"
107+
parent = "organizations/${data.google_organization.default.org_id}"
108+
location = "global"
109+
custom_intercept_profile = google_network_security_security_profile.default.id
110+
}
111+
# [END networksecurity_intercept_create_security_profile_group_tf]
112+
113+
# [START networksecurity_intercept_create_firewall_policy_tf]
114+
resource "google_compute_network_firewall_policy" "default" {
115+
provider = google-beta
116+
name = "firewall-policy"
117+
}
118+
# [END networksecurity_intercept_create_firewall_policy_tf]
119+
120+
# [START networksecurity_intercept_create_firewall_policy_rule_tf]
121+
resource "google_compute_network_firewall_policy_rule" "default" {
122+
provider = google-beta
123+
firewall_policy = google_compute_network_firewall_policy.default.name
124+
priority = 1000
125+
action = "apply_security_profile_group"
126+
direction = "INGRESS"
127+
security_profile_group = google_network_security_security_profile_group.default.id
128+
129+
match {
130+
layer4_configs {
131+
ip_protocol = "tcp"
132+
ports = ["80"]
133+
}
134+
src_ip_ranges = ["10.10.0.0/16"]
135+
}
136+
}
137+
# [END networksecurity_intercept_create_firewall_policy_rule_tf]
138+
139+
# [START networksecurity_intercept_create_firewall_policy_association_tf]
140+
resource "google_compute_network_firewall_policy_association" "default" {
141+
provider = google-beta
142+
name = "firewall-policy-assoc"
143+
attachment_target = google_compute_network.consumer_network.id
144+
firewall_policy = google_compute_network_firewall_policy.default.name
145+
}
146+
# [END networksecurity_intercept_create_firewall_policy_association_tf]
61147
# [END networksecurity_intercept_basic_consumer]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: blueprints.cloud.google.com/v1alpha1
16+
kind: BlueprintTest
17+
metadata:
18+
name: network_security_intercept_basic_consumer
19+
spec:
20+
skip: true

0 commit comments

Comments
 (0)