Skip to content
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

add deletion_protection for autonomousDatabase resource #20484

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/12298.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
oracledatabase: added `deletion_protection` field to `google_oracle_database_autonomous_database`
```
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,12 @@ projects/{project}/locations/{region}/autonomousDatabases/{autonomous_database}`
and default labels configured on the provider.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"deletion_protection": {
Type: schema.TypeBool,
Optional: true,
Description: `Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail.`,
Default: true,
},
"project": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1100,6 +1106,12 @@ func resourceOracleDatabaseAutonomousDatabaseRead(d *schema.ResourceData, meta i
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("OracleDatabaseAutonomousDatabase %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", true); err != nil {
return fmt.Errorf("Error setting deletion_protection: %s", err)
}
}
if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error reading AutonomousDatabase: %s", err)
}
Expand Down Expand Up @@ -1174,6 +1186,9 @@ func resourceOracleDatabaseAutonomousDatabaseDelete(d *schema.ResourceData, meta
}

headers := make(http.Header)
if d.Get("deletion_protection").(bool) {
return fmt.Errorf("cannot destroy google_oracle_database_autonomous_database resource with id : %q without setting deletion_protection=false and running `terraform apply`", d.Id())
}

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

// Explicitly set virtual fields to default values on import
if err := d.Set("deletion_protection", true); 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 @@ -35,6 +35,7 @@ func TestAccOracleDatabaseAutonomousDatabase_oracledatabaseAutonomousDatabaseBas

context := map[string]interface{}{
"autonomous_database_id": "my-adb-instance-id",
"deletion_protection": false,
"project": "oci-terraform-testing",
"random_suffix": acctest.RandString(t, 10),
}
Expand All @@ -51,7 +52,7 @@ func TestAccOracleDatabaseAutonomousDatabase_oracledatabaseAutonomousDatabaseBas
ResourceName: "google_oracle_database_autonomous_database.myADB",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"admin_password", "autonomous_database_id", "labels", "location", "terraform_labels"},
ImportStateVerifyIgnore: []string{"admin_password", "autonomous_database_id", "deletion_protection", "labels", "location", "terraform_labels"},
},
},
})
Expand All @@ -74,6 +75,7 @@ resource "google_oracle_database_autonomous_database" "myADB"{
db_workload = "OLTP"
license_type = "LICENSE_INCLUDED"
}
deletion_protection = "%{deletion_protection}"
}

data "google_compute_network" "default" {
Expand All @@ -88,6 +90,7 @@ func TestAccOracleDatabaseAutonomousDatabase_oracledatabaseAutonomousDatabaseFul

context := map[string]interface{}{
"autonomous_database_id": "my-adb-instance-id-2",
"deletion_protection": false,
"project": "oci-terraform-testing",
"random_suffix": acctest.RandString(t, 10),
}
Expand All @@ -104,7 +107,7 @@ func TestAccOracleDatabaseAutonomousDatabase_oracledatabaseAutonomousDatabaseFul
ResourceName: "google_oracle_database_autonomous_database.myADB",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"admin_password", "autonomous_database_id", "labels", "location", "terraform_labels"},
ImportStateVerifyIgnore: []string{"admin_password", "autonomous_database_id", "deletion_protection", "labels", "location", "terraform_labels"},
},
},
})
Expand Down Expand Up @@ -145,6 +148,7 @@ resource "google_oracle_database_autonomous_database" "myADB"{
private_endpoint_ip = "10.5.0.11"
private_endpoint_label = "testhost"
}
deletion_protection = "%{deletion_protection}"
}

data "google_compute_network" "default" {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ resource "google_oracle_database_autonomous_database" "myADB"{
db_workload = "OLTP"
license_type = "LICENSE_INCLUDED"
}
deletion_protection = "true"
}

data "google_compute_network" "default" {
Expand Down Expand Up @@ -101,6 +102,7 @@ resource "google_oracle_database_autonomous_database" "myADB"{
private_endpoint_ip = "10.5.0.11"
private_endpoint_label = "testhost"
}
deletion_protection = "true"
}

data "google_compute_network" "default" {
Expand Down Expand Up @@ -799,6 +801,7 @@ The following arguments are supported:
* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

* `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail.

## Attributes Reference

Expand Down