google_gke_backup_restore_plan

Represents a Restore Plan instance.

To get more information about RestorePlan, see:

Example Usage - Gkebackup Restoreplan All Namespaces

resource "google_container_cluster" "primary" {
  name               = "restore-all-ns-cluster"
  location           = "us-central1"
  initial_node_count = 1
  workload_identity_config {
    workload_pool = "my-project-name.svc.id.goog"
  }
  addons_config {
    gke_backup_agent_config {
      enabled = true
    }
  }
  deletion_protection  = ""
  network       = "default"
  subnetwork    = "default"
}

resource "google_gke_backup_backup_plan" "basic" {
  name = "restore-all-ns"
  cluster = google_container_cluster.primary.id
  location = "us-central1"
  backup_config {
    include_volume_data = true
    include_secrets = true
    all_namespaces = true
  }
}

resource "google_gke_backup_restore_plan" "all_ns" {
  name = "restore-all-ns"
  location = "us-central1"
  backup_plan = google_gke_backup_backup_plan.basic.id
  cluster = google_container_cluster.primary.id
  restore_config {
    all_namespaces = true
    namespaced_resource_restore_mode = "FAIL_ON_CONFLICT"
    volume_data_restore_policy = "RESTORE_VOLUME_DATA_FROM_BACKUP"
    cluster_resource_restore_scope {
      all_group_kinds = true
    }
    cluster_resource_conflict_policy = "USE_EXISTING_VERSION"
  }
}

Example Usage - Gkebackup Restoreplan Rollback Namespace

resource "google_container_cluster" "primary" {
  name               = "rollback-ns-cluster"
  location           = "us-central1"
  initial_node_count = 1
  workload_identity_config {
    workload_pool = "my-project-name.svc.id.goog"
  }
  addons_config {
    gke_backup_agent_config {
      enabled = true
    }
  }
  deletion_protection  = ""
  network       = "default"
  subnetwork    = "default"
}

resource "google_gke_backup_backup_plan" "basic" {
  name = "rollback-ns"
  cluster = google_container_cluster.primary.id
  location = "us-central1"
  backup_config {
    include_volume_data = true
    include_secrets = true
    all_namespaces = true
  }
}

resource "google_gke_backup_restore_plan" "rollback_ns" {
  name = "rollback-ns-rp"
  location = "us-central1"
  backup_plan = google_gke_backup_backup_plan.basic.id
  cluster = google_container_cluster.primary.id
  restore_config {
    selected_namespaces {
      namespaces = ["my-ns"]
    }
    namespaced_resource_restore_mode = "DELETE_AND_RESTORE"
    volume_data_restore_policy = "RESTORE_VOLUME_DATA_FROM_BACKUP"
    cluster_resource_restore_scope {
      selected_group_kinds {
        resource_group = "apiextension.k8s.io"
        resource_kind = "CustomResourceDefinition"
      }
      selected_group_kinds {
        resource_group = "storage.k8s.io"
        resource_kind = "StorageClass"
      }
    }
    cluster_resource_conflict_policy = "USE_EXISTING_VERSION"
  }
}

Example Usage - Gkebackup Restoreplan Protected Application

resource "google_container_cluster" "primary" {
  name               = "rollback-app-cluster"
  location           = "us-central1"
  initial_node_count = 1
  workload_identity_config {
    workload_pool = "my-project-name.svc.id.goog"
  }
  addons_config {
    gke_backup_agent_config {
      enabled = true
    }
  }
  deletion_protection  = ""
  network       = "default"
  subnetwork    = "default"
}

resource "google_gke_backup_backup_plan" "basic" {
  name = "rollback-app"
  cluster = google_container_cluster.primary.id
  location = "us-central1"
  backup_config {
    include_volume_data = true
    include_secrets = true
    all_namespaces = true
  }
}

resource "google_gke_backup_restore_plan" "rollback_app" {
  name = "rollback-app-rp"
  location = "us-central1"
  backup_plan = google_gke_backup_backup_plan.basic.id
  cluster = google_container_cluster.primary.id
  restore_config {
    selected_applications {
      namespaced_names {
        name = "my-app"
        namespace = "my-ns"
      }
    }
    namespaced_resource_restore_mode = "DELETE_AND_RESTORE"
    volume_data_restore_policy = "REUSE_VOLUME_HANDLE_FROM_BACKUP"
    cluster_resource_restore_scope {
      no_group_kinds = true
    }
  }
}

Example Usage - Gkebackup Restoreplan All Cluster Resources

resource "google_container_cluster" "primary" {
  name               = "all-groupkinds-cluster"
  location           = "us-central1"
  initial_node_count = 1
  workload_identity_config {
    workload_pool = "my-project-name.svc.id.goog"
  }
  addons_config {
    gke_backup_agent_config {
      enabled = true
    }
  }
  deletion_protection  = ""
  network       = "default"
  subnetwork    = "default"
}

resource "google_gke_backup_backup_plan" "basic" {
  name = "all-groupkinds"
  cluster = google_container_cluster.primary.id
  location = "us-central1"
  backup_config {
    include_volume_data = true
    include_secrets = true
    all_namespaces = true
  }
}

resource "google_gke_backup_restore_plan" "all_cluster_resources" {
  name = "all-groupkinds-rp"
  location = "us-central1"
  backup_plan = google_gke_backup_backup_plan.basic.id
  cluster = google_container_cluster.primary.id
  restore_config {
    no_namespaces = true
    namespaced_resource_restore_mode = "FAIL_ON_CONFLICT"
    cluster_resource_restore_scope {
      all_group_kinds = true
    }
    cluster_resource_conflict_policy = "USE_EXISTING_VERSION"
  }
}

Example Usage - Gkebackup Restoreplan Rename Namespace

resource "google_container_cluster" "primary" {
  name               = "rename-ns-cluster"
  location           = "us-central1"
  initial_node_count = 1
  workload_identity_config {
    workload_pool = "my-project-name.svc.id.goog"
  }
  addons_config {
    gke_backup_agent_config {
      enabled = true
    }
  }
  deletion_protection  = ""
  network       = "default"
  subnetwork    = "default"
}

resource "google_gke_backup_backup_plan" "basic" {
  name = "rename-ns"
  cluster = google_container_cluster.primary.id
  location = "us-central1"
  backup_config {
    include_volume_data = true
    include_secrets = true
    all_namespaces = true
  }
}

resource "google_gke_backup_restore_plan" "rename_ns" {
  name = "rename-ns-rp"
  location = "us-central1"
  backup_plan = google_gke_backup_backup_plan.basic.id
  cluster = google_container_cluster.primary.id
  restore_config {
    selected_namespaces {
      namespaces = ["ns1"]
    }
    namespaced_resource_restore_mode = "FAIL_ON_CONFLICT"
    volume_data_restore_policy = "REUSE_VOLUME_HANDLE_FROM_BACKUP"
    cluster_resource_restore_scope {
      no_group_kinds = true
    }
    transformation_rules {
      description = "rename namespace from ns1 to ns2"
      resource_filter {
        group_kinds {
          resource_kind = "Namespace"
        }
        json_path = ".metadata[?(@.name == 'ns1')]"
      }
      field_actions {
        op = "REPLACE"
        path = "/metadata/name"
        value = "ns2"
      }
    }
    transformation_rules {
      description = "move all resources from ns1 to ns2"
      resource_filter {
        namespaces = ["ns1"]
      }
      field_actions {
        op = "REPLACE"
        path = "/metadata/namespace"
        value = "ns2"
      }
    }
  }
}

Example Usage - Gkebackup Restoreplan Second Transformation

resource "google_container_cluster" "primary" {
  name               = "transform-rule-cluster"
  location           = "us-central1"
  initial_node_count = 1
  workload_identity_config {
    workload_pool = "my-project-name.svc.id.goog"
  }
  addons_config {
    gke_backup_agent_config {
      enabled = true
    }
  }
  deletion_protection  = ""
  network       = "default"
  subnetwork    = "default"
}

resource "google_gke_backup_backup_plan" "basic" {
  name = "transform-rule"
  cluster = google_container_cluster.primary.id
  location = "us-central1"
  backup_config {
    include_volume_data = true
    include_secrets = true
    all_namespaces = true
  }
}

resource "google_gke_backup_restore_plan" "transform_rule" {
  name = "transform-rule-rp"
  description = "copy nginx env variables"
  labels = {
    "app" = "nginx"
  }
  location = "us-central1"
  backup_plan = google_gke_backup_backup_plan.basic.id
  cluster = google_container_cluster.primary.id
  restore_config {
    excluded_namespaces {
      namespaces = ["my-ns"]
    }
    namespaced_resource_restore_mode = "DELETE_AND_RESTORE"
    volume_data_restore_policy = "RESTORE_VOLUME_DATA_FROM_BACKUP"
    cluster_resource_restore_scope {
      excluded_group_kinds {
        resource_group = "apiextension.k8s.io"
        resource_kind = "CustomResourceDefinition"
      }
    }
    cluster_resource_conflict_policy = "USE_EXISTING_VERSION"
    transformation_rules {
      description = "Copy environment variables from the nginx container to the install init container."
      resource_filter {
        group_kinds {
          resource_kind = "Pod"
          resource_group = ""
        }
        json_path = ".metadata[?(@.name == 'nginx')]"
      }
      field_actions {
        op = "COPY"
        path = "/spec/initContainers/0/env"
        from_path = "/spec/containers/0/env"
      }
    }
  }
}

Argument Reference

The following arguments are supported:

The restore_config block supports:

The excluded_namespaces block supports:

The selected_namespaces block supports:

The selected_applications block supports:

The namespaced_names block supports:

The cluster_resource_restore_scope block supports:

The excluded_group_kinds block supports:

The selected_group_kinds block supports:

The transformation_rules block supports:

The resource_filter block supports:

The group_kinds block supports:

The field_actions block supports:


Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

RestorePlan can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import RestorePlan using one of the formats above. For example:

import {
  id = "projects/{{project}}/locations/{{location}}/restorePlans/{{name}}"
  to = google_gke_backup_restore_plan.default
}

When using the terraform import command, RestorePlan can be imported using one of the formats above. For example:

$ terraform import google_gke_backup_restore_plan.default projects/{{project}}/locations/{{location}}/restorePlans/{{name}}
$ terraform import google_gke_backup_restore_plan.default {{project}}/{{location}}/{{name}}
$ terraform import google_gke_backup_restore_plan.default {{location}}/{{name}}

User Project Overrides

This resource supports User Project Overrides.