From 6f7d670e0f2e9da1ab3e562611c2a3ed25284ab3 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Mon, 25 Mar 2024 19:05:47 +0200 Subject: [PATCH] metastore - add support for scheduled backups (#10213) * add support for dataproc metastore scheduled backups * CR comments * CR comments * CR comments * CR comments * CR comments * Update mmv1/third_party/terraform/services/dataprocmetastore/resource_dataproc_metastore_service_test.go.erb Co-authored-by: Zhenhua Li * Update mmv1/third_party/terraform/services/dataprocmetastore/resource_dataproc_metastore_service_test.go.erb Co-authored-by: Zhenhua Li * CR comments --------- Co-authored-by: Zhenhua Li --- mmv1/products/metastore/Service.yaml | 29 +++++++++ ..._metastore_service_scheduled_backup.tf.erb | 31 +++++++++ ...rce_dataproc_metastore_service_test.go.erb | 64 +++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 mmv1/templates/terraform/examples/dataproc_metastore_service_scheduled_backup.tf.erb diff --git a/mmv1/products/metastore/Service.yaml b/mmv1/products/metastore/Service.yaml index 99fea8d11cbe..e85d012ae75b 100644 --- a/mmv1/products/metastore/Service.yaml +++ b/mmv1/products/metastore/Service.yaml @@ -138,6 +138,11 @@ examples: primary_resource_id: 'dpms2_scaling_factor_lt1' vars: metastore_service_name: 'ms-dpms2sflt1' + - !ruby/object:Provider::Terraform::Examples + name: 'dataproc_metastore_service_scheduled_backup' + primary_resource_id: 'backup' + vars: + metastore_service_name: 'backup' parameters: - !ruby/object:Api::Type::String name: 'serviceId' @@ -236,6 +241,30 @@ properties: description: | Scaling factor, in increments of 0.1 for values less than 1.0, and increments of 1.0 for values greater than 1.0. required: false + - !ruby/object:Api::Type::NestedObject + name: 'scheduledBackup' + description: | + The configuration of scheduled backup for the metastore service. + properties: + - !ruby/object:Api::Type::Boolean + name: 'enabled' + description: | + Defines whether the scheduled backup is enabled. The default value is false. + default_from_api: true + - !ruby/object:Api::Type::String + name: 'cronSchedule' + description: | + The scheduled interval in Cron format, see https://en.wikipedia.org/wiki/Cron The default is empty: scheduled backup is not enabled. Must be specified to enable scheduled backups. + - !ruby/object:Api::Type::String + name: 'timeZone' + description: | + Specifies the time zone to be used when interpreting cronSchedule. Must be a time zone name from the time zone database (https://en.wikipedia.org/wiki/List_of_tz_database_time_zones), e.g. America/Los_Angeles or Africa/Abidjan. If left unspecified, the default is UTC. + default_from_api: true + - !ruby/object:Api::Type::String + name: 'backupLocation' + description: | + A Cloud Storage URI of a folder, in the format gs:///. A sub-folder containing backup files will be stored below it. + required: true - !ruby/object:Api::Type::NestedObject name: 'maintenanceWindow' description: | diff --git a/mmv1/templates/terraform/examples/dataproc_metastore_service_scheduled_backup.tf.erb b/mmv1/templates/terraform/examples/dataproc_metastore_service_scheduled_backup.tf.erb new file mode 100644 index 000000000000..fe4ada3fd0bc --- /dev/null +++ b/mmv1/templates/terraform/examples/dataproc_metastore_service_scheduled_backup.tf.erb @@ -0,0 +1,31 @@ +resource "google_dataproc_metastore_service" "<%= ctx[:primary_resource_id] %>" { + service_id = "<%= ctx[:vars]['metastore_service_name'] %>" + location = "us-central1" + port = 9080 + tier = "DEVELOPER" + + maintenance_window { + hour_of_day = 2 + day_of_week = "SUNDAY" + } + + hive_metastore_config { + version = "2.3.6" + } + + scheduled_backup { + enabled = true + cron_schedule = "0 0 * * *" + time_zone = "UTC" + backup_location = "gs://${google_storage_bucket.bucket.name}" + } + + labels = { + env = "test" + } +} + +resource "google_storage_bucket" "bucket" { + name = "<%= ctx[:vars]['metastore_service_name'] %>" + location = "us-central1" +} \ No newline at end of file diff --git a/mmv1/third_party/terraform/services/dataprocmetastore/resource_dataproc_metastore_service_test.go.erb b/mmv1/third_party/terraform/services/dataprocmetastore/resource_dataproc_metastore_service_test.go.erb index 6e51622e1298..3d4460202d8c 100644 --- a/mmv1/third_party/terraform/services/dataprocmetastore/resource_dataproc_metastore_service_test.go.erb +++ b/mmv1/third_party/terraform/services/dataprocmetastore/resource_dataproc_metastore_service_test.go.erb @@ -53,6 +53,34 @@ resource "google_dataproc_metastore_service" "my_metastore" { `, name, tier) } +func TestAccDataprocMetastoreService_dataprocMetastoreServiceScheduledBackupExampleUpdate(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckDataprocMetastoreServiceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccDataprocMetastoreService_dataprocMetastoreServiceScheduledBackupExample(context), + }, + { + ResourceName: "google_dataproc_metastore_service.backup", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"service_id", "location", "labels", "terraform_labels"}, + }, + { + Config: testAccDataprocMetastoreService_dataprocMetastoreServiceScheduledBackupExampleUpdate(context), + }, + }, + }) +} + func TestAccDataprocMetastoreService_PrivateServiceConnect(t *testing.T) { t.Skip("Skipping due to https://github.com/hashicorp/terraform-provider-google/issues/13710") t.Parallel() @@ -104,3 +132,39 @@ resource "google_dataproc_metastore_service" "default" { } `, context) } + +func testAccDataprocMetastoreService_dataprocMetastoreServiceScheduledBackupExampleUpdate(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_dataproc_metastore_service" "backup" { + service_id = "tf-test-backup%{random_suffix}" + location = "us-central1" + port = 9080 + tier = "DEVELOPER" + + maintenance_window { + hour_of_day = 2 + day_of_week = "SUNDAY" + } + + hive_metastore_config { + version = "2.3.6" + } + + scheduled_backup { + enabled = true + cron_schedule = "0 0 * * 0" + time_zone = "America/Los_Angeles" + backup_location = "gs://${google_storage_bucket.bucket.name}" + } + + labels = { + env = "test" + } +} + +resource "google_storage_bucket" "bucket" { + name = "tf-test-backup%{random_suffix}" + location = "us-central1" +} +`, context) +} \ No newline at end of file