diff --git a/modules/gke-cluster-standard/README.md b/modules/gke-cluster-standard/README.md
index 71ca8c7135..2419567950 100644
--- a/modules/gke-cluster-standard/README.md
+++ b/modules/gke-cluster-standard/README.md
@@ -272,8 +272,11 @@ module "cluster-1" {
enable_backup_agent = true
backup_plans = {
"backup-1" = {
- region = "europe-west-2"
+ region = "europe-west2"
schedule = "0 9 * * 1"
+ applications = {
+ namespace-1 = ["app-1", "app-2"]
+ }
}
}
}
@@ -307,28 +310,28 @@ module "cluster-1" {
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
-| [location](variables.tf#L152) | Cluster zone or region. | string
| ✓ | |
-| [name](variables.tf#L263) | Cluster name. | string
| ✓ | |
-| [project_id](variables.tf#L289) | Cluster project id. | string
| ✓ | |
-| [vpc_config](variables.tf#L312) | VPC-level configuration. | object({…})
| ✓ | |
-| [backup_configs](variables.tf#L17) | Configuration for Backup for GKE. | object({…})
| | {}
|
-| [cluster_autoscaling](variables.tf#L37) | Enable and configure limits for Node Auto-Provisioning with Cluster Autoscaler. | object({…})
| | null
|
-| [deletion_protection](variables.tf#L58) | 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#L65) | Cluster description. | string
| | null
|
-| [enable_addons](variables.tf#L71) | Addons enabled in the cluster (true means enabled). | object({…})
| | {…}
|
-| [enable_features](variables.tf#L94) | Enable cluster-level features. Certain features allow configuration. | object({…})
| | {…}
|
-| [issue_client_certificate](variables.tf#L140) | Enable issuing client certificate. | bool
| | false
|
-| [labels](variables.tf#L146) | Cluster resource labels. | map(string)
| | null
|
-| [logging_config](variables.tf#L157) | Logging configuration. | object({…})
| | {}
|
-| [maintenance_config](variables.tf#L178) | Maintenance window configuration. | object({…})
| | {…}
|
-| [max_pods_per_node](variables.tf#L201) | Maximum number of pods per node in this cluster. | number
| | 110
|
-| [min_master_version](variables.tf#L207) | Minimum version of the master, defaults to the version of the most recent official release. | string
| | null
|
-| [monitoring_config](variables.tf#L213) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | object({…})
| | {}
|
-| [node_locations](variables.tf#L268) | Zones in which the cluster's nodes are located. | list(string)
| | []
|
-| [private_cluster_config](variables.tf#L275) | Private cluster configuration. | object({…})
| | null
|
-| [release_channel](variables.tf#L294) | Release channel for GKE upgrades. | string
| | null
|
-| [service_account](variables.tf#L300) | Service account used for the default node pool, only useful if the default GCE service account has been disabled. | string
| | null
|
-| [tags](variables.tf#L306) | 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 43bd289caa..90115501de 100644
--- a/modules/gke-cluster-standard/main.tf
+++ b/modules/gke-cluster-standard/main.tf
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
resource "google_container_cluster" "cluster" {
provider = google-beta
project = var.project_id
@@ -419,13 +418,28 @@ resource "google_gke_backup_backup_plan" "backup_plan" {
}
}
- all_namespaces = lookup(each.value, "namespaces", null) != null ? null : true
+ all_namespaces = lookup(each.value, "namespaces", null) != null || lookup(each.value, "applications", null) != null ? null : true
dynamic "selected_namespaces" {
for_each = each.value.namespaces != null ? [""] : []
content {
namespaces = each.value.namespaces
}
}
+ dynamic "selected_applications" {
+ for_each = each.value.applications != null ? [""] : []
+ content {
+ dynamic "namespaced_names" {
+ for_each = flatten([for k, vs in each.value.applications : [
+ for v in vs : { namespace = k, name = v }
+ ]])
+ content {
+ namespace = namespaced_names.value.namespace
+ name = namespaced_names.value.name
+ }
+ }
+ }
+
+ }
}
}
diff --git a/modules/gke-cluster-standard/variables.tf b/modules/gke-cluster-standard/variables.tf
index 62cfcf3c63..c88bb773e9 100644
--- a/modules/gke-cluster-standard/variables.tf
+++ b/modules/gke-cluster-standard/variables.tf
@@ -19,15 +19,16 @@ variable "backup_configs" {
type = object({
enable_backup_agent = optional(bool, false)
backup_plans = optional(map(object({
+ 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)
+ 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 b65b2a4f42..97259a3c61 100644
--- a/tests/modules/gke_cluster_standard/examples/backup.yaml
+++ b/tests/modules/gke_cluster_standard/examples/backup.yaml
@@ -19,15 +19,20 @@ values:
module.cluster-1.google_gke_backup_backup_plan.backup_plan["backup-1"]:
backup_config:
- - all_namespaces: true
+ - all_namespaces: null
encryption_key: []
include_secrets: true
include_volume_data: true
- selected_applications: []
+ selected_applications:
+ - namespaced_names:
+ - namespace: namespace-1
+ name: app-1
+ - namespace: namespace-1
+ name: app-2
selected_namespaces: []
backup_schedule:
- cron_schedule: 0 9 * * 1
- location: europe-west-2
+ location: europe-west2
name: backup-1
project: project-id
retention_policy: