diff --git a/modules/gke-cluster-standard/README.md b/modules/gke-cluster-standard/README.md
index 7337e0a025..2419567950 100644
--- a/modules/gke-cluster-standard/README.md
+++ b/modules/gke-cluster-standard/README.md
@@ -274,10 +274,9 @@ module "cluster-1" {
"backup-1" = {
region = "europe-west2"
schedule = "0 9 * * 1"
- applications = [{
- namespace = "test"
- name = "app1"
- }]
+ applications = {
+ namespace-1 = ["app-1", "app-2"]
+ }
}
}
}
@@ -311,28 +310,28 @@ module "cluster-1" {
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
-| [location](variables.tf#L156) | Cluster zone or region. | string
| ✓ | |
-| [name](variables.tf#L267) | Cluster name. | string
| ✓ | |
-| [project_id](variables.tf#L293) | Cluster project id. | string
| ✓ | |
-| [vpc_config](variables.tf#L316) | VPC-level configuration. | object({…})
| ✓ | |
-| [backup_configs](variables.tf#L17) | Configuration for Backup for GKE. | object({…})
| | {}
|
-| [cluster_autoscaling](variables.tf#L41) | Enable and configure limits for Node Auto-Provisioning with Cluster Autoscaler. | object({…})
| | null
|
-| [deletion_protection](variables.tf#L62) | Whether or not to allow Terraform to destroy the cluster. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the cluster will fail. | bool
| | true
|
-| [description](variables.tf#L69) | Cluster description. | string
| | null
|
-| [enable_addons](variables.tf#L75) | Addons enabled in the cluster (true means enabled). | object({…})
| | {…}
|
-| [enable_features](variables.tf#L98) | Enable cluster-level features. Certain features allow configuration. | object({…})
| | {…}
|
-| [issue_client_certificate](variables.tf#L144) | Enable issuing client certificate. | bool
| | false
|
-| [labels](variables.tf#L150) | Cluster resource labels. | map(string)
| | null
|
-| [logging_config](variables.tf#L161) | Logging configuration. | object({…})
| | {}
|
-| [maintenance_config](variables.tf#L182) | Maintenance window configuration. | object({…})
| | {…}
|
-| [max_pods_per_node](variables.tf#L205) | Maximum number of pods per node in this cluster. | number
| | 110
|
-| [min_master_version](variables.tf#L211) | Minimum version of the master, defaults to the version of the most recent official release. | string
| | null
|
-| [monitoring_config](variables.tf#L217) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | object({…})
| | {}
|
-| [node_locations](variables.tf#L272) | Zones in which the cluster's nodes are located. | list(string)
| | []
|
-| [private_cluster_config](variables.tf#L279) | Private cluster configuration. | object({…})
| | null
|
-| [release_channel](variables.tf#L298) | Release channel for GKE upgrades. | string
| | null
|
-| [service_account](variables.tf#L304) | Service account used for the default node pool, only useful if the default GCE service account has been disabled. | string
| | null
|
-| [tags](variables.tf#L310) | Network tags applied to nodes. | list(string)
| | null
|
+| [location](variables.tf#L153) | Cluster zone or region. | string
| ✓ | |
+| [name](variables.tf#L264) | Cluster name. | string
| ✓ | |
+| [project_id](variables.tf#L290) | Cluster project id. | string
| ✓ | |
+| [vpc_config](variables.tf#L313) | VPC-level configuration. | object({…})
| ✓ | |
+| [backup_configs](variables.tf#L17) | Configuration for Backup for GKE. | object({…})
| | {}
|
+| [cluster_autoscaling](variables.tf#L38) | Enable and configure limits for Node Auto-Provisioning with Cluster Autoscaler. | object({…})
| | null
|
+| [deletion_protection](variables.tf#L59) | Whether or not to allow Terraform to destroy the cluster. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the cluster will fail. | bool
| | true
|
+| [description](variables.tf#L66) | Cluster description. | string
| | null
|
+| [enable_addons](variables.tf#L72) | Addons enabled in the cluster (true means enabled). | object({…})
| | {…}
|
+| [enable_features](variables.tf#L95) | Enable cluster-level features. Certain features allow configuration. | object({…})
| | {…}
|
+| [issue_client_certificate](variables.tf#L141) | Enable issuing client certificate. | bool
| | false
|
+| [labels](variables.tf#L147) | Cluster resource labels. | map(string)
| | null
|
+| [logging_config](variables.tf#L158) | Logging configuration. | object({…})
| | {}
|
+| [maintenance_config](variables.tf#L179) | Maintenance window configuration. | object({…})
| | {…}
|
+| [max_pods_per_node](variables.tf#L202) | Maximum number of pods per node in this cluster. | number
| | 110
|
+| [min_master_version](variables.tf#L208) | Minimum version of the master, defaults to the version of the most recent official release. | string
| | null
|
+| [monitoring_config](variables.tf#L214) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | object({…})
| | {}
|
+| [node_locations](variables.tf#L269) | Zones in which the cluster's nodes are located. | list(string)
| | []
|
+| [private_cluster_config](variables.tf#L276) | Private cluster configuration. | object({…})
| | null
|
+| [release_channel](variables.tf#L295) | Release channel for GKE upgrades. | string
| | null
|
+| [service_account](variables.tf#L301) | Service account used for the default node pool, only useful if the default GCE service account has been disabled. | string
| | null
|
+| [tags](variables.tf#L307) | Network tags applied to nodes. | list(string)
| | null
|
## Outputs
diff --git a/modules/gke-cluster-standard/main.tf b/modules/gke-cluster-standard/main.tf
index 5b93d37ec3..91ac3e7b1e 100644
--- a/modules/gke-cluster-standard/main.tf
+++ b/modules/gke-cluster-standard/main.tf
@@ -13,7 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+locals {
+ bkp_plans_list = [for k, v in var.backup_configs.backup_plans : k]
+ bkp_namespaces_object_map = { for backup in local.bkp_plans_list : backup => flatten([
+ for k, v in var.backup_configs.backup_plans[backup].applications : [
+ for object_name in v : {
+ namespace = k
+ object_name = object_name
+ }
+ ]])
+ }
+}
resource "google_container_cluster" "cluster" {
provider = google-beta
project = var.project_id
@@ -427,12 +437,15 @@ resource "google_gke_backup_backup_plan" "backup_plan" {
}
}
dynamic "selected_applications" {
- for_each = each.value.applications != null ? each.value.applications : []
- iterator = app
+ for_each = each.value.applications != null ? [""] : []
content {
- namespaced_names {
- namespace = app.value["namespace"]
- name = app.value["name"]
+ dynamic "namespaced_names" {
+ for_each = local.bkp_namespaces_object_map[each.key]
+ iterator = ns_obj_couple
+ content {
+ namespace = ns_obj_couple.value["namespace"]
+ name = ns_obj_couple.value["object_name"]
+ }
}
}
diff --git a/modules/gke-cluster-standard/variables.tf b/modules/gke-cluster-standard/variables.tf
index 24bfc2d436..c88bb773e9 100644
--- a/modules/gke-cluster-standard/variables.tf
+++ b/modules/gke-cluster-standard/variables.tf
@@ -19,19 +19,16 @@ variable "backup_configs" {
type = object({
enable_backup_agent = optional(bool, false)
backup_plans = optional(map(object({
- applications = optional(list(object({
- namespace = string
- name = string
- })))
+ region = string
+ applications = optional(map(list(string)))
encryption_key = optional(string)
include_secrets = optional(bool, true)
include_volume_data = optional(bool, true)
namespaces = optional(list(string))
- region = string
- schedule = string
- retention_policy_days = optional(string, 1)
+ schedule = optional(string)
+ retention_policy_days = optional(number)
retention_policy_lock = optional(bool, false)
- retention_policy_delete_lock_days = optional(string)
+ retention_policy_delete_lock_days = optional(number)
})), {})
})
default = {}
diff --git a/tests/modules/gke_cluster_standard/examples/backup.yaml b/tests/modules/gke_cluster_standard/examples/backup.yaml
index 3fef633d24..259252012b 100644
--- a/tests/modules/gke_cluster_standard/examples/backup.yaml
+++ b/tests/modules/gke_cluster_standard/examples/backup.yaml
@@ -25,8 +25,11 @@ values:
include_volume_data: true
selected_applications:
- namespaced_names:
- - namespace: test
- name: app1
+ - namespace: namespace-1
+ name: app-1
+ - namespaced_names:
+ - namespace: namespace-1
+ name: app-2
selected_namespaces: []
backup_schedule:
- cron_schedule: 0 9 * * 1