Skip to content

Commit 2915bde

Browse files
Add deletion_protection field for cloudExadataInfrastructure resource (#12296) (#20485)
[upstream:df8eb1b47a810a557f8216558b4fcc8f2df3c97c] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent 4da267f commit 2915bde

7 files changed

+44
-145
lines changed

.changelog/12296.txt

Lines changed: 3 additions & 0 deletions
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_cloud_exadata_infrastructure`
3+
```

google/services/oracledatabase/resource_oracle_database_cloud_exadata_infrastructure.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ projects/{project}/locations/{region}/cloudExadataInfrastructures/{cloud_exadata
409409
and default labels configured on the provider.`,
410410
Elem: &schema.Schema{Type: schema.TypeString},
411411
},
412+
"deletion_protection": {
413+
Type: schema.TypeBool,
414+
Optional: true,
415+
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.`,
416+
Default: true,
417+
},
412418
"project": {
413419
Type: schema.TypeString,
414420
Optional: true,
@@ -561,6 +567,12 @@ func resourceOracleDatabaseCloudExadataInfrastructureRead(d *schema.ResourceData
561567
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("OracleDatabaseCloudExadataInfrastructure %q", d.Id()))
562568
}
563569

570+
// Explicitly set virtual fields to default values if unset
571+
if _, ok := d.GetOkExists("deletion_protection"); !ok {
572+
if err := d.Set("deletion_protection", true); err != nil {
573+
return fmt.Errorf("Error setting deletion_protection: %s", err)
574+
}
575+
}
564576
if err := d.Set("project", project); err != nil {
565577
return fmt.Errorf("Error reading CloudExadataInfrastructure: %s", err)
566578
}
@@ -629,6 +641,9 @@ func resourceOracleDatabaseCloudExadataInfrastructureDelete(d *schema.ResourceDa
629641
}
630642

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

633648
log.Printf("[DEBUG] Deleting CloudExadataInfrastructure %q", d.Id())
634649
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
@@ -674,6 +689,11 @@ func resourceOracleDatabaseCloudExadataInfrastructureImport(d *schema.ResourceDa
674689
}
675690
d.SetId(id)
676691

692+
// Explicitly set virtual fields to default values on import
693+
if err := d.Set("deletion_protection", true); err != nil {
694+
return nil, fmt.Errorf("Error setting deletion_protection: %s", err)
695+
}
696+
677697
return []*schema.ResourceData{d}, nil
678698
}
679699

google/services/oracledatabase/resource_oracle_database_cloud_exadata_infrastructure_generated_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func TestAccOracleDatabaseCloudExadataInfrastructure_oracledatabaseCloudExadataI
3535

3636
context := map[string]interface{}{
3737
"cloud_exadata_infrastructure_id": "ofake-exadata-basic",
38+
"deletion_protection": false,
3839
"project": "oci-terraform-testing",
3940
"random_suffix": acctest.RandString(t, 10),
4041
}
@@ -51,7 +52,7 @@ func TestAccOracleDatabaseCloudExadataInfrastructure_oracledatabaseCloudExadataI
5152
ResourceName: "google_oracle_database_cloud_exadata_infrastructure.my-cloud-exadata",
5253
ImportState: true,
5354
ImportStateVerify: true,
54-
ImportStateVerifyIgnore: []string{"cloud_exadata_infrastructure_id", "labels", "location", "terraform_labels"},
55+
ImportStateVerifyIgnore: []string{"cloud_exadata_infrastructure_id", "deletion_protection", "labels", "location", "terraform_labels"},
5556
},
5657
},
5758
})
@@ -69,6 +70,8 @@ resource "google_oracle_database_cloud_exadata_infrastructure" "my-cloud-exadata
6970
compute_count= "2"
7071
storage_count= "3"
7172
}
73+
74+
deletion_protection = "%{deletion_protection}"
7275
}
7376
`, context)
7477
}
@@ -78,6 +81,7 @@ func TestAccOracleDatabaseCloudExadataInfrastructure_oracledatabaseCloudExadataI
7881

7982
context := map[string]interface{}{
8083
"cloud_exadata_infrastructure_id": "ofake-exadata-full",
84+
"deletion_protection": false,
8185
"project": "oci-terraform-testing",
8286
"random_suffix": acctest.RandString(t, 10),
8387
}
@@ -94,7 +98,7 @@ func TestAccOracleDatabaseCloudExadataInfrastructure_oracledatabaseCloudExadataI
9498
ResourceName: "google_oracle_database_cloud_exadata_infrastructure.my-cloud-exadata",
9599
ImportState: true,
96100
ImportStateVerify: true,
97-
ImportStateVerifyIgnore: []string{"cloud_exadata_infrastructure_id", "labels", "location", "terraform_labels"},
101+
ImportStateVerifyIgnore: []string{"cloud_exadata_infrastructure_id", "deletion_protection", "labels", "location", "terraform_labels"},
98102
},
99103
},
100104
})
@@ -131,6 +135,8 @@ resource "google_oracle_database_cloud_exadata_infrastructure" "my-cloud-exadata
131135
labels = {
132136
"label-one" = "value-one"
133137
}
138+
139+
deletion_protection = "%{deletion_protection}"
134140
}
135141
`, context)
136142
}

google/services/oracledatabase/resource_oracle_database_cloud_exadata_infrastructure_sweeper.go

Lines changed: 0 additions & 143 deletions
This file was deleted.

google/services/oracledatabase/resource_oracle_database_cloud_vm_cluster_generated_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ resource "google_oracle_database_cloud_exadata_infrastructure" "cloudExadataInfr
9191
compute_count= "2"
9292
storage_count= "3"
9393
}
94+
95+
deletion_protection = "%{deletion_protection}"
9496
}
9597
9698
data "google_compute_network" "default" {
@@ -182,6 +184,8 @@ resource "google_oracle_database_cloud_exadata_infrastructure" "cloudExadataInfr
182184
compute_count= "2"
183185
storage_count= "3"
184186
}
187+
188+
deletion_protection = "%{deletion_protection}"
185189
}
186190
187191
data "google_compute_network" "default" {

website/docs/r/oracle_database_cloud_exadata_infrastructure.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ resource "google_oracle_database_cloud_exadata_infrastructure" "my-cloud-exadata
4747
compute_count= "2"
4848
storage_count= "3"
4949
}
50+
51+
deletion_protection = "true"
5052
}
5153
```
5254
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
@@ -87,6 +89,8 @@ resource "google_oracle_database_cloud_exadata_infrastructure" "my-cloud-exadata
8789
labels = {
8890
"label-one" = "value-one"
8991
}
92+
93+
deletion_protection = "true"
9094
}
9195
```
9296

@@ -132,6 +136,7 @@ The following arguments are supported:
132136
* `project` - (Optional) The ID of the project in which the resource belongs.
133137
If it is not provided, the provider project is used.
134138

139+
* `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.
135140

136141
<a name="nested_properties"></a>The `properties` block supports:
137142

website/docs/r/oracle_database_cloud_vm_cluster.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ resource "google_oracle_database_cloud_exadata_infrastructure" "cloudExadataInfr
6767
compute_count= "2"
6868
storage_count= "3"
6969
}
70+
71+
deletion_protection = "true"
7072
}
7173
7274
data "google_compute_network" "default" {
@@ -134,6 +136,8 @@ resource "google_oracle_database_cloud_exadata_infrastructure" "cloudExadataInfr
134136
compute_count= "2"
135137
storage_count= "3"
136138
}
139+
140+
deletion_protection = "true"
137141
}
138142
139143
data "google_compute_network" "default" {

0 commit comments

Comments
 (0)