google_gke_backup_backup_plan

Represents a Backup Plan instance.

To get more information about BackupPlan, see:

Example Usage - Gkebackup Backupplan Basic

resource "google_container_cluster" "primary" {
  name               = "basic-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  = "true"
  network       = "default"
  subnetwork    = "default"
}

resource "google_gke_backup_backup_plan" "basic" {
  name = "basic-plan"
  cluster = google_container_cluster.primary.id
  location = "us-central1"
  backup_config {
    include_volume_data = true
    include_secrets = true
    all_namespaces = true
  }
}
Open in Cloud Shell

Example Usage - Gkebackup Backupplan Autopilot

resource "google_container_cluster" "primary" {
  name               = "autopilot-cluster"
  location           = "us-central1"
  enable_autopilot = true
  ip_allocation_policy {   
  }
  release_channel {
    channel = "RAPID"
  }
  addons_config {
    gke_backup_agent_config {
      enabled = true
    }
  }
  deletion_protection  = "true"
  network       = "default"
  subnetwork    = "default"
}

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

Example Usage - Gkebackup Backupplan Cmek

resource "google_container_cluster" "primary" {
  name               = "cmek-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  = "true"
  network       = "default"
  subnetwork    = "default"
}

resource "google_gke_backup_backup_plan" "cmek" {
  name = "cmek-plan"
  cluster = google_container_cluster.primary.id
  location = "us-central1"
  backup_config {
    include_volume_data = true
    include_secrets = true
    selected_namespaces {
      namespaces = ["default", "test"]
    }
    encryption_key {
      gcp_kms_encryption_key = google_kms_crypto_key.crypto_key.id
    }
  }
}

resource "google_kms_crypto_key" "crypto_key" {
  name     = "backup-key"
  key_ring = google_kms_key_ring.key_ring.id
}

resource "google_kms_key_ring" "key_ring" {
  name     = "backup-key"
  location = "us-central1"
}

Example Usage - Gkebackup Backupplan Full

resource "google_container_cluster" "primary" {
  name               = "full-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  = "true"
  network       = "default"
  subnetwork    = "default"
}

resource "google_gke_backup_backup_plan" "full" {
  name = "full-plan"
  cluster = google_container_cluster.primary.id
  location = "us-central1"
  retention_policy {
    backup_delete_lock_days = 30
    backup_retain_days = 180
  }
  backup_schedule {
    cron_schedule = "0 9 * * 1"
  }
  backup_config {
    include_volume_data = true
    include_secrets = true
    selected_applications {
      namespaced_names {
        name = "app1"
        namespace = "ns1"
      }
      namespaced_names {
        name = "app2"
        namespace = "ns2"
      }
    }
  }
}

Example Usage - Gkebackup Backupplan Rpo Daily Window

resource "google_container_cluster" "primary" {
  name               = "rpo-daily-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  = "true"
  network       = "default"
  subnetwork    = "default"
}

resource "google_gke_backup_backup_plan" "rpo_daily_window" {
  name = "rpo-daily-window"
  cluster = google_container_cluster.primary.id
  location = "us-central1"
  retention_policy {
    backup_delete_lock_days = 30
    backup_retain_days = 180
  }
  backup_schedule {
    paused = true
    rpo_config {
      target_rpo_minutes=1440
      exclusion_windows {
        start_time  {
          hours = 12
        }
        duration = "7200s"
        daily = true
      }
      exclusion_windows {
        start_time  {
          hours = 8
          minutes = 40
          seconds = 1
          nanos = 100
        }
        duration = "3600s"
        single_occurrence_date {
          year = 2024
          month = 3
          day = 16
        }
      }
    }
  }
  backup_config {
    include_volume_data = true
    include_secrets = true
    all_namespaces = true
  }
}

Example Usage - Gkebackup Backupplan Rpo Weekly Window

resource "google_container_cluster" "primary" {
  name               = "rpo-weekly-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  = "true"
  network       = "default"
  subnetwork    = "default"
}

resource "google_gke_backup_backup_plan" "rpo_weekly_window" {
  name = "rpo-weekly-window"
  cluster = google_container_cluster.primary.id
  location = "us-central1"
  retention_policy {
    backup_delete_lock_days = 30
    backup_retain_days = 180
  }
  backup_schedule {
    paused = true
    rpo_config {
      target_rpo_minutes=1440
      exclusion_windows {
        start_time  {
          hours = 1
          minutes = 23
        }
        duration = "1800s"
        days_of_week {
          days_of_week = ["MONDAY", "THURSDAY"]
        }
      }
      exclusion_windows {
        start_time  {
          hours = 12
        }
        duration = "3600s"
        single_occurrence_date {
          year = 2024
          month = 3
          day = 17
        }
      }
      exclusion_windows {
        start_time  {
          hours = 8
          minutes = 40
        }
        duration = "600s"
        single_occurrence_date {
          year = 2024
          month = 3
          day = 18
        }
      }
    }
  }
  backup_config {
    include_volume_data = true
    include_secrets = true
    all_namespaces = true
  }
}

Argument Reference

The following arguments are supported:


The retention_policy block supports:

The backup_schedule block supports:

The rpo_config block supports:

The exclusion_windows block supports:

The start_time block supports:

The single_occurrence_date block supports:

The days_of_week block supports:

The backup_config block supports:

The encryption_key block supports:

The selected_namespaces block supports:

The selected_applications block supports:

The namespaced_names 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

BackupPlan can be imported using any of these accepted formats:

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

import {
  id = "projects/{{project}}/locations/{{location}}/backupPlans/{{name}}"
  to = google_gke_backup_backup_plan.default
}

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

$ terraform import google_gke_backup_backup_plan.default projects/{{project}}/locations/{{location}}/backupPlans/{{name}}
$ terraform import google_gke_backup_backup_plan.default {{project}}/{{location}}/{{name}}
$ terraform import google_gke_backup_backup_plan.default {{location}}/{{name}}

User Project Overrides

This resource supports User Project Overrides.