|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | +package dataprocmetastore_test |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 8 | + "regexp" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 12 | +) |
| 13 | + |
| 14 | +func TestAccMetastoreFederation_deletionprotection(t *testing.T) { |
| 15 | + t.Parallel() |
| 16 | + |
| 17 | + name := "tf-test-metastore-" + acctest.RandString(t, 10) |
| 18 | + |
| 19 | + acctest.VcrTest(t, resource.TestCase{ |
| 20 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 21 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 22 | + Steps: []resource.TestStep{ |
| 23 | + { |
| 24 | + Config: testAccMetastoreFederationDeletionProtection(name, "us-central1"), |
| 25 | + }, |
| 26 | + { |
| 27 | + ResourceName: "google_dataproc_metastore_federation.default", |
| 28 | + ImportState: true, |
| 29 | + ImportStateVerify: true, |
| 30 | + ImportStateVerifyIgnore: []string{"deletion_protection"}, |
| 31 | + }, |
| 32 | + { |
| 33 | + Config: testAccMetastoreFederationDeletionProtection(name, "us-west2"), |
| 34 | + ExpectError: regexp.MustCompile("deletion_protection"), |
| 35 | + }, |
| 36 | + { |
| 37 | + Config: testAccMetastoreFederationDeletionProtectionFalse(name, "us-central1"), |
| 38 | + }, |
| 39 | + { |
| 40 | + ResourceName: "google_dataproc_metastore_federation.default", |
| 41 | + ImportState: true, |
| 42 | + ImportStateVerify: true, |
| 43 | + ImportStateVerifyIgnore: []string{"deletion_protection"}, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }) |
| 47 | +} |
| 48 | + |
| 49 | +func testAccMetastoreFederationDeletionProtection(name string, location string) string { |
| 50 | + |
| 51 | + return fmt.Sprintf(` |
| 52 | + resource "google_dataproc_metastore_service" "default" { |
| 53 | + service_id = "%s" |
| 54 | + location = "us-central1" |
| 55 | + tier = "DEVELOPER" |
| 56 | + hive_metastore_config { |
| 57 | + version = "3.1.2" |
| 58 | + endpoint_protocol = "GRPC" |
| 59 | + } |
| 60 | + } |
| 61 | + resource "google_dataproc_metastore_federation" "default" { |
| 62 | + federation_id = "%s" |
| 63 | + location = "%s" |
| 64 | + version = "3.1.2" |
| 65 | + deletion_protection = true |
| 66 | + backend_metastores { |
| 67 | + rank = "1" |
| 68 | + name = google_dataproc_metastore_service.default.id |
| 69 | + metastore_type = "DATAPROC_METASTORE" |
| 70 | + } |
| 71 | +} |
| 72 | +`, name, name, location) |
| 73 | +} |
| 74 | + |
| 75 | +func testAccMetastoreFederationDeletionProtectionFalse(name string, location string) string { |
| 76 | + |
| 77 | + return fmt.Sprintf(` |
| 78 | + resource "google_dataproc_metastore_service" "default" { |
| 79 | + service_id = "%s" |
| 80 | + location = "us-central1" |
| 81 | + tier = "DEVELOPER" |
| 82 | + hive_metastore_config { |
| 83 | + version = "3.1.2" |
| 84 | + endpoint_protocol = "GRPC" |
| 85 | + } |
| 86 | + } |
| 87 | + resource "google_dataproc_metastore_federation" "default" { |
| 88 | + federation_id = "%s" |
| 89 | + location = "%s" |
| 90 | + version = "3.1.2" |
| 91 | + deletion_protection = false |
| 92 | + backend_metastores { |
| 93 | + rank = "1" |
| 94 | + name = google_dataproc_metastore_service.default.id |
| 95 | + metastore_type = "DATAPROC_METASTORE" |
| 96 | + } |
| 97 | +} |
| 98 | +`, name, name, location) |
| 99 | +} |
0 commit comments