Skip to content

Commit 2b3bb11

Browse files
duvniglasntiennae
authored andcommitted
feat(networksecurity): Add examples for creating consumer and producer mirroring (terraform-google-modules#798)
* feat(networksecurity): Add examples for creating consumer and producer mirroring * Enable networksecurity API * Add codeowners for network security's mirroring samples * Use default as Terraform resource names where possible * Rename association resource to default * Fix tab discrepancy in CODEOWNERS file --------- Co-authored-by: Katie McLaughlin <[email protected]> Co-authored-by: Jennifer Davis <[email protected]>
1 parent f2315bb commit 2b3bb11

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START networksecurity_mirroring_basic_consumer]
18+
resource "google_compute_network" "producer_network" {
19+
provider = google-beta
20+
name = "producer-network"
21+
auto_create_subnetworks = false
22+
}
23+
24+
resource "google_compute_network" "consumer_network" {
25+
provider = google-beta
26+
name = "consumer-network"
27+
auto_create_subnetworks = false
28+
}
29+
30+
resource "google_network_security_mirroring_deployment_group" "default" {
31+
provider = google-beta
32+
mirroring_deployment_group_id = "mirroring-deployment-group"
33+
location = "global"
34+
network = google_compute_network.producer_network.id
35+
}
36+
37+
resource "google_network_security_mirroring_endpoint_group" "default" {
38+
provider = google-beta
39+
mirroring_endpoint_group_id = "mirroring-endpoint-group"
40+
location = "global"
41+
mirroring_deployment_group = google_network_security_mirroring_deployment_group.default.id
42+
}
43+
44+
resource "google_network_security_mirroring_endpoint_group_association" "default" {
45+
provider = google-beta
46+
mirroring_endpoint_group_association_id = "mirroring-endpoint-group-association"
47+
location = "global"
48+
network = google_compute_network.consumer_network.id
49+
mirroring_endpoint_group = google_network_security_mirroring_endpoint_group.default.id
50+
}
51+
# [END networksecurity_mirroring_basic_consumer]
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START networksecurity_mirroring_basic_producer]
18+
resource "google_compute_network" "default" {
19+
provider = google-beta
20+
name = "producer-network"
21+
auto_create_subnetworks = false
22+
}
23+
24+
resource "google_compute_subnetwork" "default" {
25+
provider = google-beta
26+
name = "producer-subnet"
27+
region = "us-central1"
28+
ip_cidr_range = "10.1.0.0/16"
29+
network = google_compute_network.default.name
30+
}
31+
32+
resource "google_compute_region_health_check" "default" {
33+
provider = google-beta
34+
name = "deploymnet-hc"
35+
region = "us-central1"
36+
http_health_check {
37+
port = 80
38+
}
39+
}
40+
41+
resource "google_compute_region_backend_service" "default" {
42+
provider = google-beta
43+
name = "deployment-svc"
44+
region = "us-central1"
45+
health_checks = [google_compute_region_health_check.default.id]
46+
protocol = "UDP"
47+
load_balancing_scheme = "INTERNAL"
48+
}
49+
50+
resource "google_compute_forwarding_rule" "default" {
51+
provider = google-beta
52+
name = "deployment-fr"
53+
region = "us-central1"
54+
network = google_compute_network.default.name
55+
subnetwork = google_compute_subnetwork.default.name
56+
backend_service = google_compute_region_backend_service.default.id
57+
load_balancing_scheme = "INTERNAL"
58+
ports = [6081]
59+
ip_protocol = "UDP"
60+
is_mirroring_collector = true
61+
}
62+
63+
resource "google_network_security_mirroring_deployment_group" "default" {
64+
provider = google-beta
65+
mirroring_deployment_group_id = "mirroring-deployment-group"
66+
location = "global"
67+
network = google_compute_network.default.id
68+
}
69+
70+
resource "google_network_security_mirroring_deployment" "default" {
71+
provider = google-beta
72+
mirroring_deployment_id = "mirroring-deployment"
73+
location = "us-central1-a"
74+
forwarding_rule = google_compute_forwarding_rule.default.id
75+
mirroring_deployment_group = google_network_security_mirroring_deployment_group.default.id
76+
}
77+
# [END networksecurity_mirroring_basic_producer]

0 commit comments

Comments
 (0)