diff --git a/backupdr/backup_plan/main.tf b/backupdr/backup_plan/main.tf index 1ea38877..32db16a3 100644 --- a/backupdr/backup_plan/main.tf +++ b/backupdr/backup_plan/main.tf @@ -48,6 +48,7 @@ resource "google_backup_dr_backup_plan" "default" { backup_plan_id = "my-bp" resource_type = "compute.googleapis.com/Instance" backup_vault = google_backup_dr_backup_vault.default.name + # log_retention_days = 2 # Only applicable for Cloud SQL backup_rules { rule_id = "rule-1" diff --git a/backupdr/backup_plan_association/main.tf b/backupdr/backup_plan_association/main.tf index 667414ec..b7576557 100644 --- a/backupdr/backup_plan_association/main.tf +++ b/backupdr/backup_plan_association/main.tf @@ -59,6 +59,24 @@ resource "google_compute_disk" "default" { zone = "us-central1-a" } +resource "google_sql_database_instance" "default" { + name = "instance-test" + database_version = "MYSQL_8_0_41" + region = "us-central1" + settings { + tier = "db-f1-micro" + backup_configuration { + enabled = true + } + } + lifecycle { + ignore_changes = [ + settings[0].backup_configuration[0].enabled, + ] + } + deletion_protection = false +} + resource "google_backup_dr_backup_vault" "default" { provider = google-beta location = "us-central1" @@ -129,6 +147,31 @@ resource "google_backup_dr_backup_plan" "disk_default" { } } +resource "google_backup_dr_backup_plan" "csql_default" { + provider = google-beta + location = "us-central1" + backup_plan_id = "my-csql-bp" + resource_type = "sqladmin.googleapis.com/Instance" + backup_vault = google_backup_dr_backup_vault.default.name + log_retention_days = 2 + + backup_rules { + rule_id = "rule-1" + backup_retention_days = 7 + + standard_schedule { + recurrence_type = "HOURLY" + hourly_frequency = 6 + time_zone = "UTC" + + backup_window { + start_hour_of_day = 0 + end_hour_of_day = 23 + } + } + } +} + # [START backupdr_create_backupplanassociation] # Before creating a backup plan association, you need to create backup plan (google_backup_dr_backup_plan) @@ -158,3 +201,18 @@ resource "google_backup_dr_backup_plan_association" "disk_association" { } # [END backupdr_create_backupplanassociation_disk] + +# [START backupdr_create_backupplanassociation_csql] + +# Before creating a backup plan association, you need to create backup plan (google_backup_dr_backup_plan) +# and Cloud SQL Instance (google_sql_database_instance). +resource "google_backup_dr_backup_plan_association" "csql_association" { + provider = google-beta + location = "us-central1" + backup_plan_association_id = "my-csql-bpa" + resource = "projects/${google_sql_database_instance.default.project}/instances/${google_sql_database_instance.default.name}" + resource_type = "sqladmin.googleapis.com/Instance" + backup_plan = google_backup_dr_backup_plan.csql_default.name +} + +# [END backupdr_create_backupplanassociation_csql]