Skip to content

Commit

Permalink
metastore - add support for scheduled backups (GoogleCloudPlatform#10213
Browse files Browse the repository at this point in the history
)

* 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 <[email protected]>

* Update mmv1/third_party/terraform/services/dataprocmetastore/resource_dataproc_metastore_service_test.go.erb

Co-authored-by: Zhenhua Li <[email protected]>

* CR comments

---------

Co-authored-by: Zhenhua Li <[email protected]>
  • Loading branch information
2 people authored and cmfeng committed Apr 5, 2024
1 parent b315e52 commit 89ffa6e
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
29 changes: 29 additions & 0 deletions mmv1/products/metastore/Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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://<bucket_name>/<path_inside_bucket>. A sub-folder <backup_folder> containing backup files will be stored below it.
required: true
- !ruby/object:Api::Type::NestedObject
name: 'maintenanceWindow'
description: |
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}

0 comments on commit 89ffa6e

Please sign in to comment.