@@ -23,7 +23,7 @@ data "google_project" "project" {
2323}
2424
2525resource "random_string" "random_suffix" {
26- length = 6
26+ length = 4
2727 special = false
2828 lower = true
2929 upper = false
@@ -39,6 +39,10 @@ resource "google_compute_network" "network_backup" {
3939 name = " ${ local . prefix } -network-backup"
4040}
4141
42+ # ###############################
43+ # Tags #
44+ # ###############################
45+
4246resource "google_tags_tag_key" "tag_key" {
4347
4448 description = " For keyname resources."
@@ -56,6 +60,10 @@ resource "google_tags_tag_value" "tag_value" {
5660 short_name = " yes"
5761}
5862
63+ # ###############################
64+ # Address group #
65+ # ###############################
66+
5967resource "google_network_security_address_group" "networksecurity_address_group" {
6068 provider = google- beta
6169
@@ -68,25 +76,32 @@ resource "google_network_security_address_group" "networksecurity_address_group"
6876 capacity = 100
6977}
7078
79+ # ###############################
80+ # Service Account #
81+ # ###############################
82+
7183resource "google_service_account" "service_account" {
7284 project = var. project_id
7385 account_id = " ${ local . prefix } -fw-test-svc-acct"
7486 display_name = " ${ local . prefix } firewall policy test service account"
7587}
7688
7789# ###############################
78- # VPC Spoke #
90+ # VPC #
7991# ###############################
92+
8093module "vpc" {
8194 source = " terraform-google-modules/network/google//modules/vpc"
8295 version = " ~> 10.0"
8396
8497 project_id = var. project_id
8598 network_name = " global-sec-policy-test-vpc"
86-
87- # shared_vpc_host = false
8899}
89100
101+ # ###############################
102+ # Mirroring #
103+ # ###############################
104+
90105resource "google_network_security_mirroring_deployment_group" "mirroring_deployment_group" {
91106 project = var. project_id
92107 mirroring_deployment_group_id = " ${ local . prefix } -mirroring-dg"
@@ -104,13 +119,11 @@ resource "google_network_security_mirroring_endpoint_group" "mirroring_endpoint_
104119 mirroring_deployment_group = google_network_security_mirroring_deployment_group. mirroring_deployment_group . id
105120}
106121
107-
108122resource "google_network_security_security_profile" "security_profile" {
109- provider = google- beta
110- name = " ${ local . prefix } -security-profile"
111- parent = " organizations/${ var . org_id } "
112- description = " Security profile description"
113- type = " CUSTOM_MIRRORING"
123+ provider = google- beta
124+ name = " ${ local . prefix } -mirror-sp-${ random_string . random_suffix . result } "
125+ parent = " organizations/${ var . org_id } "
126+ type = " CUSTOM_MIRRORING"
114127
115128 custom_mirroring_profile {
116129 mirroring_endpoint_group = google_network_security_mirroring_endpoint_group. mirroring_endpoint_group . id
@@ -119,13 +132,33 @@ resource "google_network_security_security_profile" "security_profile" {
119132
120133resource "google_network_security_security_profile_group" "security_profile_group" {
121134 provider = google- beta
122- name = " ${ local . prefix } -sec-profile-group "
135+ name = " ${ local . prefix } -mirror-spg- ${ random_string . random_suffix . result } "
123136 parent = " organizations/${ var . org_id } "
124- description = " Security profile group"
125137 custom_mirroring_profile = google_network_security_security_profile. security_profile . id
126138}
127139
140+ # ###############################
141+ # Threat #
142+ # ###############################
143+
144+ resource "google_network_security_security_profile" "security_profile_1" {
145+ provider = google- beta
146+ name = " ${ local . prefix } -threat-sp-${ random_string . random_suffix . result } "
147+ type = " THREAT_PREVENTION"
148+ parent = " organizations/${ var . org_id } "
149+ location = " global"
150+ }
151+
152+ resource "google_network_security_security_profile_group" "security_profile_group_1" {
153+ provider = google- beta
154+ name = " ${ local . prefix } -threat-spg-${ random_string . random_suffix . result } "
155+ parent = " organizations/${ var . org_id } "
156+ threat_prevention_profile = google_network_security_security_profile. security_profile_1 . id
157+ }
128158
159+ # ###############################
160+ # Firewall Policy #
161+ # ###############################
129162
130163module "firewal_policy" {
131164 source = " terraform-google-modules/network/google//modules/network-firewall-policy"
@@ -259,16 +292,14 @@ module "firewal_policy" {
259292 }
260293 },
261294 {
262- is_mirroring = true
263- priority = " 200"
264- direction = " EGRESS"
265- action = " mirror"
266- rule_name = " egress-200"
267- disabled = false
268- description = " test egress mirroring rule 200"
269- target_service_accounts = [" fw-test-svc-acct@${ var . project_id } .iam.gserviceaccount.com" ]
295+ is_mirroring = true
296+ priority = " 200"
297+ direction = " EGRESS"
298+ action = " mirror"
299+ rule_name = " egress-200"
300+ disabled = false
301+ description = " test egress mirroring rule 200"
270302 match = {
271- src_ip_ranges = [" 0.0.0.0/0" ]
272303 dest_ip_ranges = [" 0.0.0.0/0" ]
273304 layer4_configs = [
274305 {
@@ -279,6 +310,23 @@ module "firewal_policy" {
279310 }
280311 security_profile_group_id = google_network_security_security_profile_group.security_profile_group.id
281312 },
313+ {
314+ priority = " 300"
315+ direction = " EGRESS"
316+ action = " apply_security_profile_group"
317+ rule_name = " egress-300"
318+ disabled = false
319+ description = " test egress threat prevention rule 300"
320+ match = {
321+ dest_ip_ranges = [" 0.0.0.0/0" ]
322+ layer4_configs = [
323+ {
324+ ip_protocol = " tcp"
325+ }
326+ ]
327+ }
328+ security_profile_group_id = google_network_security_security_profile_group.security_profile_group_1.id
329+ },
282330
283331 ]
284332
@@ -289,8 +337,9 @@ module "firewal_policy" {
289337}
290338
291339module "firewal_policy_no_rule" {
292- source = " terraform-google-modules/network/google//modules/network-firewall-policy"
293- version = " ~> 11.0"
340+ source = " terraform-google-modules/network/google//modules/network-firewall-policy"
341+ version = " ~> 11.0"
342+
294343 project_id = var. project_id
295344 policy_name = " ${ local . prefix } -firewall-policy-no-rules-${ random_string . random_suffix . result } "
296345 description = " ${ local . prefix } test firewall policy without any rules"
0 commit comments