Skip to content

Commit

Permalink
Allow setting GKE cluster deletion protection
Browse files Browse the repository at this point in the history
Starting with provider version 5, GKE requires deletion protection
to be applied as false explicitly. Otherwise a destroy of the
cluster will fail.
  • Loading branch information
pst committed Jan 9, 2024
1 parent 65f999e commit faa7ecd
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions google/_modules/gke/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ resource "google_container_cluster" "current" {
project = var.project
name = var.metadata_name

deletion_protection = var.deletion_protection

location = var.location
node_locations = var.node_locations

Expand Down
5 changes: 5 additions & 0 deletions google/_modules/gke/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ variable "project" {
description = "Project the cluster belongs to."
}

variable "deletion_protection" {
type = bool
description = "Must be set to false to destroy clusters."
}

variable "metadata_name" {
type = string
description = "Metadata name to use."
Expand Down
2 changes: 2 additions & 0 deletions google/cluster/configuration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ locals {

region = local.cfg["region"]

deletion_protection = lookup(local.cfg, "deletion_protection", null)

cluster_node_locations_lookup = lookup(local.cfg, "cluster_node_locations", "")
cluster_node_locations = split(",", local.cluster_node_locations_lookup)

Expand Down
2 changes: 2 additions & 0 deletions google/cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module "cluster" {

project = local.project_id

deletion_protection = local.deletion_protection

metadata_name = module.cluster_metadata.name
metadata_fqdn = module.cluster_metadata.fqdn
metadata_tags = module.cluster_metadata.tags
Expand Down
2 changes: 2 additions & 0 deletions tests/gke_zero_cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module "gke_zero" {
configuration = {
# Settings for Apps-cluster
apps = {
deletion_protection = false

project_id = "terraform-kubestack-testing"
name_prefix = "kbstacctest"
base_domain = "infra.serverwolken.de"
Expand Down

0 comments on commit faa7ecd

Please sign in to comment.