Skip to content

Add deletion_protection field to Metastore Federation #9674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/13471.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
metastore: added `deletion_protection` field to `google_dataproc_metastore_federation`
```
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ resource "google_dataproc_metastore_service" "default" {
version = "3.1.2"
endpoint_protocol = "GRPC"
}
deletion_protection = false
}

resource "google_dataproc_metastore_federation_iam_member" "foo" {
Expand Down Expand Up @@ -153,6 +154,7 @@ resource "google_dataproc_metastore_service" "default" {
version = "3.1.2"
endpoint_protocol = "GRPC"
}
deletion_protection = false
}

data "google_iam_policy" "foo" {
Expand Down Expand Up @@ -204,6 +206,7 @@ resource "google_dataproc_metastore_service" "default" {
version = "3.1.2"
endpoint_protocol = "GRPC"
}
deletion_protection = false
}

data "google_iam_policy" "foo" {
Expand Down Expand Up @@ -242,6 +245,7 @@ resource "google_dataproc_metastore_service" "default" {
version = "3.1.2"
endpoint_protocol = "GRPC"
}
deletion_protection = false
}

resource "google_dataproc_metastore_federation_iam_binding" "foo" {
Expand Down Expand Up @@ -278,6 +282,7 @@ resource "google_dataproc_metastore_service" "default" {
version = "3.1.2"
endpoint_protocol = "GRPC"
}
deletion_protection = false
}

resource "google_dataproc_metastore_federation_iam_binding" "foo" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ Please refer to the field 'effective_labels' for all of the labels present on th
Computed: true,
Description: `Output only. The time when the metastore federation was last updated.`,
},
"deletion_protection": {
Type: schema.TypeBool,
Optional: true,
Description: `Whether Terraform will be prevented from destroying the federation. Defaults to false.
When the field is set to true in Terraform state, a 'terraform apply'
or 'terraform destroy' that would delete the federation will fail.`,
Default: false,
},
"project": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -291,6 +299,12 @@ func resourceDataprocMetastoreFederationRead(d *schema.ResourceData, meta interf
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("DataprocMetastoreFederation %q", d.Id()))
}

// Explicitly set virtual fields to default values if unset
if _, ok := d.GetOkExists("deletion_protection"); !ok {
if err := d.Set("deletion_protection", false); err != nil {
return fmt.Errorf("Error setting deletion_protection: %s", err)
}
}
if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error reading Federation: %s", err)
}
Expand Down Expand Up @@ -451,6 +465,9 @@ func resourceDataprocMetastoreFederationDelete(d *schema.ResourceData, meta inte
}

headers := make(http.Header)
if d.Get("deletion_protection").(bool) {
return fmt.Errorf("cannot destroy metastore federation without setting deletion_protection=false and running `terraform apply`")
}

log.Printf("[DEBUG] Deleting Federation %q", d.Id())
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Expand Down Expand Up @@ -496,6 +513,11 @@ func resourceDataprocMetastoreFederationImport(d *schema.ResourceData, meta inte
}
d.SetId(id)

// Explicitly set virtual fields to default values on import
if err := d.Set("deletion_protection", false); err != nil {
return nil, fmt.Errorf("Error setting deletion_protection: %s", err)
}

return []*schema.ResourceData{d}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ fields:
- field: 'backend_metastores.backend_metastores.metastore_type'
- field: 'backend_metastores.backend_metastores.name'
- field: 'create_time'
- field: 'deletion_protection'
provider_only: true
- field: 'effective_labels'
provider_only: true
- field: 'endpoint_uri'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestAccDataprocMetastoreFederation_dataprocMetastoreFederationBasicExample(
ResourceName: "google_dataproc_metastore_federation.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"federation_id", "labels", "location", "terraform_labels"},
ImportStateVerifyIgnore: []string{"deletion_protection", "federation_id", "labels", "location", "terraform_labels"},
},
},
})
Expand Down Expand Up @@ -79,6 +79,7 @@ resource "google_dataproc_metastore_service" "default" {
version = "3.1.2"
endpoint_protocol = "GRPC"
}
deletion_protection = false
}
`, context)
}
Expand Down

This file was deleted.

Loading
Loading