Skip to content

Commit cc293e8

Browse files
add deletion_protection for autonomousDatabase resource (#12298)
[upstream:6eb3aa904157f7fe8e11671c669f2b6f5a355c18] Signed-off-by: Modular Magician <[email protected]>
1 parent c3b9a03 commit cc293e8

5 files changed

+32
-145
lines changed

.changelog/12298.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
oracledatabase: added `deletion_protection` field to `google_oracle_database_autonomous_database`
3+
```

google-beta/services/oracledatabase/resource_oracle_database_autonomous_database.go

+20
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,12 @@ projects/{project}/locations/{region}/autonomousDatabases/{autonomous_database}`
930930
and default labels configured on the provider.`,
931931
Elem: &schema.Schema{Type: schema.TypeString},
932932
},
933+
"deletion_protection": {
934+
Type: schema.TypeBool,
935+
Optional: true,
936+
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.`,
937+
Default: true,
938+
},
933939
"project": {
934940
Type: schema.TypeString,
935941
Optional: true,
@@ -1100,6 +1106,12 @@ func resourceOracleDatabaseAutonomousDatabaseRead(d *schema.ResourceData, meta i
11001106
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("OracleDatabaseAutonomousDatabase %q", d.Id()))
11011107
}
11021108

1109+
// Explicitly set virtual fields to default values if unset
1110+
if _, ok := d.GetOkExists("deletion_protection"); !ok {
1111+
if err := d.Set("deletion_protection", true); err != nil {
1112+
return fmt.Errorf("Error setting deletion_protection: %s", err)
1113+
}
1114+
}
11031115
if err := d.Set("project", project); err != nil {
11041116
return fmt.Errorf("Error reading AutonomousDatabase: %s", err)
11051117
}
@@ -1174,6 +1186,9 @@ func resourceOracleDatabaseAutonomousDatabaseDelete(d *schema.ResourceData, meta
11741186
}
11751187

11761188
headers := make(http.Header)
1189+
if d.Get("deletion_protection").(bool) {
1190+
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())
1191+
}
11771192

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

1237+
// Explicitly set virtual fields to default values on import
1238+
if err := d.Set("deletion_protection", true); err != nil {
1239+
return nil, fmt.Errorf("Error setting deletion_protection: %s", err)
1240+
}
1241+
12221242
return []*schema.ResourceData{d}, nil
12231243
}
12241244

google-beta/services/oracledatabase/resource_oracle_database_autonomous_database_generated_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func TestAccOracleDatabaseAutonomousDatabase_oracledatabaseAutonomousDatabaseBas
3535

3636
context := map[string]interface{}{
3737
"autonomous_database_id": "my-adb-instance-id",
38+
"deletion_protection": false,
3839
"project": "oci-terraform-testing",
3940
"random_suffix": acctest.RandString(t, 10),
4041
}
@@ -51,7 +52,7 @@ func TestAccOracleDatabaseAutonomousDatabase_oracledatabaseAutonomousDatabaseBas
5152
ResourceName: "google_oracle_database_autonomous_database.myADB",
5253
ImportState: true,
5354
ImportStateVerify: true,
54-
ImportStateVerifyIgnore: []string{"admin_password", "autonomous_database_id", "labels", "location", "terraform_labels"},
55+
ImportStateVerifyIgnore: []string{"admin_password", "autonomous_database_id", "deletion_protection", "labels", "location", "terraform_labels"},
5556
},
5657
},
5758
})
@@ -74,6 +75,7 @@ resource "google_oracle_database_autonomous_database" "myADB"{
7475
db_workload = "OLTP"
7576
license_type = "LICENSE_INCLUDED"
7677
}
78+
deletion_protection = "%{deletion_protection}"
7779
}
7880
7981
data "google_compute_network" "default" {
@@ -88,6 +90,7 @@ func TestAccOracleDatabaseAutonomousDatabase_oracledatabaseAutonomousDatabaseFul
8890

8991
context := map[string]interface{}{
9092
"autonomous_database_id": "my-adb-instance-id-2",
93+
"deletion_protection": false,
9194
"project": "oci-terraform-testing",
9295
"random_suffix": acctest.RandString(t, 10),
9396
}
@@ -104,7 +107,7 @@ func TestAccOracleDatabaseAutonomousDatabase_oracledatabaseAutonomousDatabaseFul
104107
ResourceName: "google_oracle_database_autonomous_database.myADB",
105108
ImportState: true,
106109
ImportStateVerify: true,
107-
ImportStateVerifyIgnore: []string{"admin_password", "autonomous_database_id", "labels", "location", "terraform_labels"},
110+
ImportStateVerifyIgnore: []string{"admin_password", "autonomous_database_id", "deletion_protection", "labels", "location", "terraform_labels"},
108111
},
109112
},
110113
})
@@ -145,6 +148,7 @@ resource "google_oracle_database_autonomous_database" "myADB"{
145148
private_endpoint_ip = "10.5.0.11"
146149
private_endpoint_label = "testhost"
147150
}
151+
deletion_protection = "%{deletion_protection}"
148152
}
149153
150154
data "google_compute_network" "default" {

google-beta/services/oracledatabase/resource_oracle_database_autonomous_database_sweeper.go

-143
This file was deleted.

website/docs/r/oracle_database_autonomous_database.html.markdown

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ resource "google_oracle_database_autonomous_database" "myADB"{
5252
db_workload = "OLTP"
5353
license_type = "LICENSE_INCLUDED"
5454
}
55+
deletion_protection = "true"
5556
}
5657
5758
data "google_compute_network" "default" {
@@ -101,6 +102,7 @@ resource "google_oracle_database_autonomous_database" "myADB"{
101102
private_endpoint_ip = "10.5.0.11"
102103
private_endpoint_label = "testhost"
103104
}
105+
deletion_protection = "true"
104106
}
105107
106108
data "google_compute_network" "default" {
@@ -799,6 +801,7 @@ The following arguments are supported:
799801
* `project` - (Optional) The ID of the project in which the resource belongs.
800802
If it is not provided, the provider project is used.
801803

804+
* `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.
802805

803806
## Attributes Reference
804807

0 commit comments

Comments
 (0)