Skip to content

Commit a3edb10

Browse files
authored
feat(networksecurity): Add samples for mirroring rule creation (#840)
1 parent 74fe876 commit a3edb10

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

network_security/mirroring/basic/consumer/main.tf

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

17+
data "google_project" "default" {}
18+
19+
# In case the project is in a folder, extract the organization ID from it.
20+
data "google_folder" "default" {
21+
count = data.google_project.default.folder_id != "" ? 1 : 0
22+
folder = data.google_project.default.folder_id
23+
lookup_organization = true
24+
}
25+
26+
data "google_organization" "default" {
27+
organization = data.google_project.default.org_id != "" ? data.google_project.default.org_id : data.google_folder.default[0].organization
28+
}
29+
1730
# [START networksecurity_mirroring_basic_consumer]
1831
# [START networksecurity_mirroring_create_producer_network_tf]
1932
resource "google_compute_network" "producer_network" {
@@ -29,6 +42,15 @@ resource "google_compute_network" "consumer_network" {
2942
}
3043
# [END networksecurity_mirroring_create_consumer_network_tf]
3144

45+
# [START networksecurity_mirroring_create_consumer_subnetwork_tf]
46+
resource "google_compute_subnetwork" "consumer_subnet" {
47+
name = "consumer-subnet"
48+
region = "us-central1"
49+
ip_cidr_range = "10.10.0.0/16"
50+
network = google_compute_network.consumer_network.name
51+
}
52+
# [END networksecurity_mirroring_create_consumer_subnetwork_tf]
53+
3254
# [START networksecurity_mirroring_create_producer_deployment_group_tf]
3355
resource "google_network_security_mirroring_deployment_group" "default" {
3456
mirroring_deployment_group_id = "mirroring-deployment-group"
@@ -53,4 +75,59 @@ resource "google_network_security_mirroring_endpoint_group_association" "default
5375
mirroring_endpoint_group = google_network_security_mirroring_endpoint_group.default.id
5476
}
5577
# [END networksecurity_mirroring_create_endpoint_group_association_tf]
78+
79+
# [START networksecurity_mirroring_create_security_profile_tf]
80+
resource "google_network_security_security_profile" "default" {
81+
name = "security-profile"
82+
type = "CUSTOM_MIRRORING"
83+
parent = "organizations/${data.google_organization.default.org_id}"
84+
location = "global"
85+
86+
custom_mirroring_profile {
87+
mirroring_endpoint_group = google_network_security_mirroring_endpoint_group.default.id
88+
}
89+
}
90+
# [END networksecurity_mirroring_create_security_profile_tf]
91+
92+
# [START networksecurity_mirroring_create_security_profile_group_tf]
93+
resource "google_network_security_security_profile_group" "default" {
94+
name = "security-profile-group"
95+
parent = "organizations/${data.google_organization.default.org_id}"
96+
location = "global"
97+
custom_mirroring_profile = google_network_security_security_profile.default.id
98+
}
99+
# [END networksecurity_mirroring_create_security_profile_group_tf]
100+
101+
# [START networksecurity_mirroring_create_firewall_policy_tf]
102+
resource "google_compute_network_firewall_policy" "default" {
103+
name = "firewall-policy"
104+
}
105+
# [END networksecurity_mirroring_create_firewall_policy_tf]
106+
107+
# [START networksecurity_mirroring_create_firewall_policy_rule_tf]
108+
resource "google_compute_network_firewall_policy_packet_mirroring_rule" "default" {
109+
provider = google-beta
110+
firewall_policy = google_compute_network_firewall_policy.default.name
111+
priority = 1000
112+
action = "mirror"
113+
direction = "INGRESS"
114+
security_profile_group = google_network_security_security_profile_group.default.id
115+
116+
match {
117+
layer4_configs {
118+
ip_protocol = "tcp"
119+
ports = ["80"]
120+
}
121+
src_ip_ranges = ["10.10.0.0/16"]
122+
}
123+
}
124+
# [END networksecurity_mirroring_create_firewall_policy_rule_tf]
125+
126+
# [START networksecurity_mirroring_create_firewall_policy_association_tf]
127+
resource "google_compute_network_firewall_policy_association" "default" {
128+
name = "firewall-policy-assoc"
129+
attachment_target = google_compute_network.consumer_network.id
130+
firewall_policy = google_compute_network_firewall_policy.default.name
131+
}
132+
# [END networksecurity_mirroring_create_firewall_policy_association_tf]
56133
# [END networksecurity_mirroring_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_mirroring_basic_consumer
19+
spec:
20+
skip: true

0 commit comments

Comments
 (0)