Skip to content

Commit 1708c12

Browse files
Fix for hierarchical firewall policy
1 parent 779f8dd commit 1708c12

File tree

4 files changed

+45
-51
lines changed

4 files changed

+45
-51
lines changed

3-networks-dual-svpc/modules/hierarchical_firewall_policy/main.tf

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
locals {
18-
policy_id = google_compute_organization_security_policy.policy.id
18+
policy_id = google_compute_firewall_policy.policy.id
1919
}
2020

2121
resource "random_string" "suffix" {
@@ -24,17 +24,15 @@ resource "random_string" "suffix" {
2424
special = false
2525
}
2626

27-
resource "google_compute_organization_security_policy" "policy" {
28-
provider = google-beta
29-
display_name = "${var.name}-${random_string.suffix.result}"
30-
parent = var.parent
27+
resource "google_compute_firewall_policy" "policy" {
28+
short_name = "${var.name}-${random_string.suffix.result}"
29+
parent = var.parent
3130
}
3231

33-
resource "google_compute_organization_security_policy_rule" "rule" {
34-
provider = google-beta
32+
resource "google_compute_firewall_policy_rule" "rule" {
3533
for_each = var.rules
3634

37-
policy_id = google_compute_organization_security_policy.policy.id
35+
firewall_policy = google_compute_firewall_policy.policy.id
3836
action = each.value.action
3937
direction = each.value.direction
4038
priority = each.value.priority
@@ -44,25 +42,24 @@ resource "google_compute_organization_security_policy_rule" "rule" {
4442
# preview = each.value.preview
4543
match {
4644
# description = each.value.description
47-
config {
48-
src_ip_ranges = each.value.direction == "INGRESS" ? each.value.ranges : null
49-
dest_ip_ranges = each.value.direction == "EGRESS" ? each.value.ranges : null
50-
dynamic "layer4_config" {
51-
for_each = each.value.ports
52-
iterator = port
53-
content {
54-
ip_protocol = port.key
55-
ports = port.value
56-
}
45+
46+
src_ip_ranges = each.value.direction == "INGRESS" ? each.value.ranges : null
47+
dest_ip_ranges = each.value.direction == "EGRESS" ? each.value.ranges : null
48+
dynamic "layer4_configs" {
49+
for_each = each.value.ports
50+
iterator = port
51+
content {
52+
ip_protocol = port.key
53+
ports = port.value
5754
}
5855
}
5956
}
6057
}
6158

62-
resource "google_compute_organization_security_policy_association" "association" {
63-
provider = google-beta
64-
for_each = toset(var.associations)
65-
name = "${local.policy_id}-${each.value}"
66-
policy_id = local.policy_id
67-
attachment_id = each.value
59+
resource "google_compute_firewall_policy_association" "association" {
60+
for_each = toset(var.associations)
61+
62+
name = replace("${local.policy_id}-${each.value}", "/", "-")
63+
firewall_policy = google_compute_firewall_policy.policy.id
64+
attachment_target = each.value
6865
}

3-networks-dual-svpc/modules/hierarchical_firewall_policy/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
*/
1616

1717
output "id" {
18-
value = google_compute_organization_security_policy.policy.id
18+
value = google_compute_firewall_policy.policy.id
1919
}
Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022 Google LLC
2+
* Copyright 2021 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
1515
*/
1616

1717
locals {
18-
policy_id = google_compute_organization_security_policy.policy.id
18+
policy_id = google_compute_firewall_policy.policy.id
1919
}
2020

2121
resource "random_string" "suffix" {
@@ -24,17 +24,15 @@ resource "random_string" "suffix" {
2424
special = false
2525
}
2626

27-
resource "google_compute_organization_security_policy" "policy" {
28-
provider = google-beta
29-
display_name = "${var.name}-${random_string.suffix.result}"
30-
parent = var.parent
27+
resource "google_compute_firewall_policy" "policy" {
28+
short_name = "${var.name}-${random_string.suffix.result}"
29+
parent = var.parent
3130
}
3231

33-
resource "google_compute_organization_security_policy_rule" "rule" {
34-
provider = google-beta
32+
resource "google_compute_firewall_policy_rule" "rule" {
3533
for_each = var.rules
3634

37-
policy_id = google_compute_organization_security_policy.policy.id
35+
firewall_policy = google_compute_firewall_policy.policy.id
3836
action = each.value.action
3937
direction = each.value.direction
4038
priority = each.value.priority
@@ -44,25 +42,24 @@ resource "google_compute_organization_security_policy_rule" "rule" {
4442
# preview = each.value.preview
4543
match {
4644
# description = each.value.description
47-
config {
48-
src_ip_ranges = each.value.direction == "INGRESS" ? each.value.ranges : null
49-
dest_ip_ranges = each.value.direction == "EGRESS" ? each.value.ranges : null
50-
dynamic "layer4_config" {
51-
for_each = each.value.ports
52-
iterator = port
53-
content {
54-
ip_protocol = port.key
55-
ports = port.value
56-
}
45+
46+
src_ip_ranges = each.value.direction == "INGRESS" ? each.value.ranges : null
47+
dest_ip_ranges = each.value.direction == "EGRESS" ? each.value.ranges : null
48+
dynamic "layer4_configs" {
49+
for_each = each.value.ports
50+
iterator = port
51+
content {
52+
ip_protocol = port.key
53+
ports = port.value
5754
}
5855
}
5956
}
6057
}
6158

62-
resource "google_compute_organization_security_policy_association" "association" {
63-
provider = google-beta
64-
for_each = toset(var.associations)
65-
name = "${local.policy_id}-${each.value}"
66-
policy_id = local.policy_id
67-
attachment_id = each.value
59+
resource "google_compute_firewall_policy_association" "association" {
60+
for_each = toset(var.associations)
61+
62+
name = replace("${local.policy_id}-${each.value}", "/", "-")
63+
firewall_policy = google_compute_firewall_policy.policy.id
64+
attachment_target = each.value
6865
}

3-networks-hub-and-spoke/modules/hierarchical_firewall_policy/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
*/
1616

1717
output "id" {
18-
value = google_compute_organization_security_policy.policy.id
18+
value = google_compute_firewall_policy.policy.id
1919
}

0 commit comments

Comments
 (0)