Skip to content

Commit adb1a51

Browse files
committed
fix: make fw more specific and toggleable, use CFT for DNS
1 parent fed031c commit adb1a51

File tree

4 files changed

+64
-70
lines changed

4 files changed

+64
-70
lines changed

2-networks/modules/standard_shared_vpc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
| Name | Description | Type | Default | Required |
55
|------|-------------|:----:|:-----:|:-----:|
66
| bgp\_asn | BGP ASN for default cloud router. | string | n/a | yes |
7+
| default\_fw\_rules\_enabled | Toggle creation of default firewall rules. | bool | `"true"` | no |
78
| default\_region | Default subnet region standard_shared_vpc currently only configures one region. | string | n/a | yes |
89
| dns\_enable\_inbound\_forwarding | Toggle inbound query forwarding for VPC DNS. | bool | `"true"` | no |
910
| dns\_enable\_logging | Toggle DNS logging for VPC DNS. | bool | `"true"` | no |

2-networks/modules/standard_shared_vpc/dns.tf

Lines changed: 48 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -33,80 +33,64 @@ resource "google_dns_policy" "default_policy" {
3333
Private Google APIs DNS Zone & records.
3434
*****************************************/
3535

36-
resource "google_dns_managed_zone" "private_googleapis" {
37-
provider = google-beta
38-
project = var.project_id
36+
module "private_googleapis" {
37+
source = "terraform-google-modules/cloud-dns/google"
38+
version = "~> 3.0"
39+
project_id = var.project_id
40+
type = "private"
3941
name = "private-googleapis"
40-
dns_name = "googleapis.com."
42+
domain = "googleapis.com."
4143
description = "Private DNS zone to configure private.googleapis.com"
4244

43-
visibility = "private"
44-
45-
private_visibility_config {
46-
networks {
47-
network_url = module.main.network_self_link
48-
}
49-
}
50-
}
51-
52-
resource "google_dns_record_set" "googleapis_cname" {
53-
provider = google-beta
54-
project = var.project_id
55-
name = "*.googleapis.com."
56-
managed_zone = google_dns_managed_zone.private_googleapis.name
57-
type = "CNAME"
58-
ttl = 300
59-
rrdatas = ["private.googleapis.com."]
60-
}
61-
62-
resource "google_dns_record_set" "private_googleapis_a" {
63-
provider = google-beta
64-
project = var.project_id
65-
name = "private.googleapis.com."
66-
managed_zone = google_dns_managed_zone.private_googleapis.name
67-
type = "A"
68-
ttl = 300
69-
70-
rrdatas = ["199.36.153.8", "199.36.153.9", "199.36.153.10", "199.36.153.11"]
45+
private_visibility_config_networks = [
46+
module.main.network_self_link
47+
]
48+
49+
recordsets = [
50+
{
51+
name = "*"
52+
type = "CNAME"
53+
ttl = 300
54+
records = ["private.googleapis.com."]
55+
},
56+
{
57+
name = "private"
58+
type = "A"
59+
ttl = 300
60+
records = ["199.36.153.8", "199.36.153.9", "199.36.153.10", "199.36.153.11"]
61+
},
62+
]
7163
}
7264

7365
/******************************************
7466
Private GCR DNS Zone & records.
7567
*****************************************/
7668

77-
resource "google_dns_managed_zone" "private_gcr" {
78-
provider = google-beta
79-
project = var.project_id
69+
module "private_gcr" {
70+
source = "terraform-google-modules/cloud-dns/google"
71+
version = "~> 3.0"
72+
project_id = var.project_id
73+
type = "private"
8074
name = "private-gcr"
81-
dns_name = "gcr.io."
75+
domain = "gcr.io."
8276
description = "Private DNS zone to configure gcr.io"
8377

84-
visibility = "private"
85-
86-
private_visibility_config {
87-
networks {
88-
network_url = module.main.network_self_link
89-
}
90-
}
91-
}
92-
93-
resource "google_dns_record_set" "gcr_cname" {
94-
provider = google-beta
95-
project = var.project_id
96-
name = "*.gcr.io."
97-
managed_zone = google_dns_managed_zone.private_gcr.name
98-
type = "CNAME"
99-
ttl = 300
100-
rrdatas = ["gcr.io."]
101-
}
102-
103-
resource "google_dns_record_set" "private_gcr_a" {
104-
provider = google-beta
105-
project = var.project_id
106-
name = "gcr.io."
107-
managed_zone = google_dns_managed_zone.private_gcr.name
108-
type = "A"
109-
ttl = 300
110-
111-
rrdatas = ["199.36.153.8", "199.36.153.9", "199.36.153.10", "199.36.153.11"]
78+
private_visibility_config_networks = [
79+
module.main.network_self_link
80+
]
81+
82+
recordsets = [
83+
{
84+
name = "*"
85+
type = "CNAME"
86+
ttl = 300
87+
records = ["gcr.io."]
88+
},
89+
{
90+
name = ""
91+
type = "A"
92+
ttl = 300
93+
records = ["199.36.153.8", "199.36.153.9", "199.36.153.10", "199.36.153.11"]
94+
},
95+
]
11296
}

2-networks/modules/standard_shared_vpc/firewall.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
*****************************************/
2020

2121
// Allow SSH when using the allow-ssh tag for Linux workloads.
22-
resource "google_compute_firewall" "allow_ssh" {
23-
name = "allow-ssh"
22+
resource "google_compute_firewall" "allow_iap_ssh" {
23+
count = var.default_fw_rules_enabled ? 1 : 0
24+
name = "allow-iap-ssh"
2425
network = module.main.network_name
2526
project = var.project_id
2627

@@ -32,12 +33,13 @@ resource "google_compute_firewall" "allow_ssh" {
3233
ports = ["22"]
3334
}
3435

35-
target_tags = ["allow-ssh"]
36+
target_tags = ["allow-iap-ssh"]
3637
}
3738

3839
// Allow RDP when using the allow-rdp tag for Windows workloads.
39-
resource "google_compute_firewall" "allow_rdp" {
40-
name = "allow-rdp"
40+
resource "google_compute_firewall" "allow_iap_rdp" {
41+
count = var.default_fw_rules_enabled ? 1 : 0
42+
name = "allow-iap-rdp"
4143
network = module.main.network_name
4244
project = var.project_id
4345

@@ -49,11 +51,12 @@ resource "google_compute_firewall" "allow_rdp" {
4951
ports = ["3389"]
5052
}
5153

52-
target_tags = ["allow-rdp"]
54+
target_tags = ["allow-iap-rdp"]
5355
}
5456

5557
// Allow traffic for Internal & Global load balancing health check and load balancing IP ranges.
5658
resource "google_compute_firewall" "allow_lb" {
59+
count = var.default_fw_rules_enabled ? 1 : 0
5760
name = "allow-lb"
5861
network = module.main.network_name
5962
project = var.project_id

2-networks/modules/standard_shared_vpc/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,9 @@ variable "nat_num_addresses" {
6868
description = "Number of external IPs to reserve for Cloud NAT."
6969
default = 2
7070
}
71+
72+
variable "default_fw_rules_enabled" {
73+
type = bool
74+
description = "Toggle creation of default firewall rules."
75+
default = true
76+
}

0 commit comments

Comments
 (0)