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]
1932resource "google_compute_network" "producer_network" {
20- provider = google- beta
2133 name = " producer-network"
2234 auto_create_subnetworks = false
2335}
2436# [END networksecurity_mirroring_create_producer_network_tf]
2537
2638# [START networksecurity_mirroring_create_consumer_network_tf]
2739resource "google_compute_network" "consumer_network" {
28- provider = google- beta
2940 name = " consumer-network"
3041 auto_create_subnetworks = false
3142}
3243# [END networksecurity_mirroring_create_consumer_network_tf]
3344
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+
3454# [START networksecurity_mirroring_create_producer_deployment_group_tf]
3555resource "google_network_security_mirroring_deployment_group" "default" {
36- provider = google- beta
3756 mirroring_deployment_group_id = " mirroring-deployment-group"
3857 location = " global"
3958 network = google_compute_network. producer_network . id
@@ -42,7 +61,6 @@ resource "google_network_security_mirroring_deployment_group" "default" {
4261
4362# [START networksecurity_mirroring_create_endpoint_group_tf]
4463resource "google_network_security_mirroring_endpoint_group" "default" {
45- provider = google- beta
4664 mirroring_endpoint_group_id = " mirroring-endpoint-group"
4765 location = " global"
4866 mirroring_deployment_group = google_network_security_mirroring_deployment_group. default . id
@@ -51,11 +69,65 @@ resource "google_network_security_mirroring_endpoint_group" "default" {
5169
5270# [START networksecurity_mirroring_create_endpoint_group_association_tf]
5371resource "google_network_security_mirroring_endpoint_group_association" "default" {
54- provider = google- beta
5572 mirroring_endpoint_group_association_id = " mirroring-endpoint-group-association"
5673 location = " global"
5774 network = google_compute_network. consumer_network . id
5875 mirroring_endpoint_group = google_network_security_mirroring_endpoint_group. default . id
5976}
6077# [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]
61133# [END networksecurity_mirroring_basic_consumer]
0 commit comments