Skip to content

Commit ca18dbc

Browse files
feat: Add private endpoint subnetwork variable for safer cluster modules (#2540)
Co-authored-by: Andrew Peabody <andrewpeabody@google.com>
1 parent 4f3c404 commit ca18dbc

12 files changed

Lines changed: 38 additions & 3 deletions

File tree

autogen/safer-cluster/main.tf.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ module "gke" {
140140
// We enable private endpoints to limit exposure.
141141
enable_private_endpoint = var.enable_private_endpoint
142142
deploy_using_private_endpoint = true
143+
private_endpoint_subnetwork = var.private_endpoint_subnetwork
143144

144145
// Private nodes better control public exposure, and reduce
145146
// the ability of nodes to reach to the Internet without
@@ -148,7 +149,7 @@ module "gke" {
148149

149150
master_global_access_enabled = true
150151

151-
master_ipv4_cidr_block = var.master_ipv4_cidr_block
152+
master_ipv4_cidr_block = var.private_endpoint_subnetwork != null ? null : var.master_ipv4_cidr_block
152153

153154
cloudrun = var.cloudrun
154155

autogen/safer-cluster/variables.tf.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ variable "master_ipv4_cidr_block" {
323323
default = "10.0.0.0/28"
324324
}
325325

326+
variable "private_endpoint_subnetwork" {
327+
type = string
328+
description = "The subnetwork to use for the hosted master network. If specified, `master_ipv4_cidr_block` is ignored."
329+
default = null
330+
}
331+
326332
variable "dns_cache" {
327333
type = bool
328334
description = "(Beta) The status of the NodeLocal DNSCache addon."

modules/safer-cluster-update-variant/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ For simplicity, we suggest using `roles/container.admin` and
266266
| node\_pools\_tags | Map of lists containing node network tags by node-pool name | `map(list(string))` | <pre>{<br> "all": [],<br> "default-node-pool": []<br>}</pre> | no |
267267
| node\_pools\_taints | Map of lists containing node taints by node-pool name | `map(list(object({ key = string, value = string, effect = string })))` | <pre>{<br> "all": [],<br> "default-node-pool": []<br>}</pre> | no |
268268
| notification\_config\_topic | The desired Pub/Sub topic to which notifications will be sent by GKE. Format is projects/{project}/topics/{topic}. | `string` | `""` | no |
269+
| private\_endpoint\_subnetwork | The subnetwork to use for the hosted master network. If specified, `master_ipv4_cidr_block` is ignored. | `string` | `null` | no |
269270
| project\_id | The project ID to host the cluster in | `string` | n/a | yes |
270271
| region | The region to host the cluster in | `string` | n/a | yes |
271272
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | `bool` | `true` | no |

modules/safer-cluster-update-variant/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ module "gke" {
136136
// We enable private endpoints to limit exposure.
137137
enable_private_endpoint = var.enable_private_endpoint
138138
deploy_using_private_endpoint = true
139+
private_endpoint_subnetwork = var.private_endpoint_subnetwork
139140

140141
// Private nodes better control public exposure, and reduce
141142
// the ability of nodes to reach to the Internet without
@@ -144,7 +145,7 @@ module "gke" {
144145

145146
master_global_access_enabled = true
146147

147-
master_ipv4_cidr_block = var.master_ipv4_cidr_block
148+
master_ipv4_cidr_block = var.private_endpoint_subnetwork != null ? null : var.master_ipv4_cidr_block
148149

149150
cloudrun = var.cloudrun
150151

modules/safer-cluster-update-variant/metadata.display.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ spec:
223223
notification_config_topic:
224224
name: notification_config_topic
225225
title: Notification Config Topic
226+
private_endpoint_subnetwork:
227+
name: private_endpoint_subnetwork
228+
title: Private Endpoint Subnetwork
226229
project_id:
227230
name: project_id
228231
title: Project Id

modules/safer-cluster-update-variant/metadata.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ spec:
337337
description: The IP range in CIDR notation to use for the hosted master network
338338
varType: string
339339
defaultValue: 10.0.0.0/28
340+
- name: private_endpoint_subnetwork
341+
description: The subnetwork to use for the hosted master network. If specified, `master_ipv4_cidr_block` is ignored.
342+
varType: string
340343
- name: dns_cache
341344
description: (Beta) The status of the NodeLocal DNSCache addon.
342345
varType: bool

modules/safer-cluster-update-variant/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ variable "master_ipv4_cidr_block" {
323323
default = "10.0.0.0/28"
324324
}
325325

326+
variable "private_endpoint_subnetwork" {
327+
type = string
328+
description = "The subnetwork to use for the hosted master network. If specified, `master_ipv4_cidr_block` is ignored."
329+
default = null
330+
}
331+
326332
variable "dns_cache" {
327333
type = bool
328334
description = "(Beta) The status of the NodeLocal DNSCache addon."

modules/safer-cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ For simplicity, we suggest using `roles/container.admin` and
266266
| node\_pools\_tags | Map of lists containing node network tags by node-pool name | `map(list(string))` | <pre>{<br> "all": [],<br> "default-node-pool": []<br>}</pre> | no |
267267
| node\_pools\_taints | Map of lists containing node taints by node-pool name | `map(list(object({ key = string, value = string, effect = string })))` | <pre>{<br> "all": [],<br> "default-node-pool": []<br>}</pre> | no |
268268
| notification\_config\_topic | The desired Pub/Sub topic to which notifications will be sent by GKE. Format is projects/{project}/topics/{topic}. | `string` | `""` | no |
269+
| private\_endpoint\_subnetwork | The subnetwork to use for the hosted master network. If specified, `master_ipv4_cidr_block` is ignored. | `string` | `null` | no |
269270
| project\_id | The project ID to host the cluster in | `string` | n/a | yes |
270271
| region | The region to host the cluster in | `string` | n/a | yes |
271272
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | `bool` | `true` | no |

modules/safer-cluster/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ module "gke" {
136136
// We enable private endpoints to limit exposure.
137137
enable_private_endpoint = var.enable_private_endpoint
138138
deploy_using_private_endpoint = true
139+
private_endpoint_subnetwork = var.private_endpoint_subnetwork
139140

140141
// Private nodes better control public exposure, and reduce
141142
// the ability of nodes to reach to the Internet without
@@ -144,7 +145,7 @@ module "gke" {
144145

145146
master_global_access_enabled = true
146147

147-
master_ipv4_cidr_block = var.master_ipv4_cidr_block
148+
master_ipv4_cidr_block = var.private_endpoint_subnetwork != null ? null : var.master_ipv4_cidr_block
148149

149150
cloudrun = var.cloudrun
150151

modules/safer-cluster/metadata.display.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ spec:
223223
notification_config_topic:
224224
name: notification_config_topic
225225
title: Notification Config Topic
226+
private_endpoint_subnetwork:
227+
name: private_endpoint_subnetwork
228+
title: Private Endpoint Subnetwork
226229
project_id:
227230
name: project_id
228231
title: Project Id

0 commit comments

Comments
 (0)