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" {
@@ -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]
3355resource "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]
0 commit comments