Skip to content

Commit

Permalink
Merge pull request #329 from kbst/gke-deletion-protection
Browse files Browse the repository at this point in the history
Allow setting GKE cluster deletion protection
  • Loading branch information
pst authored Jan 9, 2024
2 parents 524477e + faa7ecd commit 7a95548
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 7a95548

Please sign in to comment.