Skip to content

Commit d6bdf2f

Browse files
committed
feat(networksecurity): Add samples for intercept firewall rule creation
1 parent efce91d commit d6bdf2f

File tree

1 file changed

+18
-7
lines changed
  • network_security/intercept/basic/consumer

1 file changed

+18
-7
lines changed

network_security/intercept/basic/consumer/main.tf

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

17+
data "google_project" "default" {
18+
provider = google-beta
19+
}
20+
21+
# In case the project is in a folder, extract the organization ID from it.
22+
data "google_folder" "default" {
23+
count = data.google_project.default.folder_id != "" ? 1 : 0
24+
folder = data.google_project.default.folder_id
25+
lookup_organization = true
26+
}
27+
28+
data "google_organization" "default" {
29+
provider = google-beta
30+
organization = data.google_project.default.org_id != "" ? data.google_project.default.org_id : data.google_folder.default[0].organization
31+
}
32+
1733
# [START networksecurity_intercept_basic_consumer]
1834
# [START networksecurity_intercept_create_producer_network_tf]
1935
resource "google_compute_network" "producer_network" {
@@ -69,12 +85,6 @@ resource "google_network_security_intercept_endpoint_group_association" "default
6985
}
7086
# [END networksecurity_intercept_create_endpoint_group_association_tf]
7187

72-
data "google_project" "default" {}
73-
74-
data "google_organization" "default" {
75-
organization = data.google_project.default.org_id
76-
}
77-
7888
# [START networksecurity_intercept_create_security_profile_tf]
7989
resource "google_network_security_security_profile" "default" {
8090
provider = google-beta
@@ -113,7 +123,7 @@ resource "google_compute_network_firewall_policy_rule" "default" {
113123
priority = 1000
114124
action = "apply_security_profile_group"
115125
direction = "INGRESS"
116-
security_profile_group = "//networksecurity.googleapis.com/${google_network_security_security_profile_group.default.id}"
126+
security_profile_group = google_network_security_security_profile_group.default.id
117127

118128
match {
119129
layer4_configs {
@@ -127,6 +137,7 @@ resource "google_compute_network_firewall_policy_rule" "default" {
127137

128138
# [START networksecurity_intercept_create_firewall_policy_association_tf]
129139
resource "google_compute_network_firewall_policy_association" "default" {
140+
provider = google-beta
130141
name = "firewall-policy-assoc"
131142
attachment_target = google_compute_network.consumer_network.id
132143
firewall_policy = google_compute_network_firewall_policy.default.name

0 commit comments

Comments
 (0)