Skip to content

Commit faa7ecd

Browse files
committed
Allow setting GKE cluster deletion protection
Starting with provider version 5, GKE requires deletion protection to be applied as false explicitly. Otherwise a destroy of the cluster will fail.
1 parent 65f999e commit faa7ecd

File tree

5 files changed

+13
-0
lines changed

5 files changed

+13
-0
lines changed

google/_modules/gke/cluster.tf

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ resource "google_container_cluster" "current" {
22
project = var.project
33
name = var.metadata_name
44

5+
deletion_protection = var.deletion_protection
6+
57
location = var.location
68
node_locations = var.node_locations
79

google/_modules/gke/variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ variable "project" {
33
description = "Project the cluster belongs to."
44
}
55

6+
variable "deletion_protection" {
7+
type = bool
8+
description = "Must be set to false to destroy clusters."
9+
}
10+
611
variable "metadata_name" {
712
type = string
813
description = "Metadata name to use."

google/cluster/configuration.tf

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ locals {
1717

1818
region = local.cfg["region"]
1919

20+
deletion_protection = lookup(local.cfg, "deletion_protection", null)
21+
2022
cluster_node_locations_lookup = lookup(local.cfg, "cluster_node_locations", "")
2123
cluster_node_locations = split(",", local.cluster_node_locations_lookup)
2224

google/cluster/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module "cluster" {
1313

1414
project = local.project_id
1515

16+
deletion_protection = local.deletion_protection
17+
1618
metadata_name = module.cluster_metadata.name
1719
metadata_fqdn = module.cluster_metadata.fqdn
1820
metadata_tags = module.cluster_metadata.tags

tests/gke_zero_cluster.tf

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ module "gke_zero" {
1414
configuration = {
1515
# Settings for Apps-cluster
1616
apps = {
17+
deletion_protection = false
18+
1719
project_id = "terraform-kubestack-testing"
1820
name_prefix = "kbstacctest"
1921
base_domain = "infra.serverwolken.de"

0 commit comments

Comments
 (0)