Skip to content

Commit

Permalink
Add deletion_protection field in cloudvmcluster resource (#12297) (#2…
Browse files Browse the repository at this point in the history
…0392)

[upstream:77315f8f88322e7bc019cc42437b56124448329c]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Nov 19, 2024
1 parent 1d52876 commit 132e7b4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 145 deletions.
3 changes: 3 additions & 0 deletions .changelog/12297.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_cloud_vm_cluster `
```
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ projects/{project}/locations/{region}/cloudVmClusters/{cloud_vm_cluster}`,
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 @@ -577,6 +583,12 @@ func resourceOracleDatabaseCloudVmClusterRead(d *schema.ResourceData, meta inter
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("OracleDatabaseCloudVmCluster %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 CloudVmCluster: %s", err)
}
Expand Down Expand Up @@ -654,6 +666,9 @@ func resourceOracleDatabaseCloudVmClusterDelete(d *schema.ResourceData, meta int
}

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

log.Printf("[DEBUG] Deleting CloudVmCluster %q", d.Id())
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Expand Down Expand Up @@ -699,6 +714,11 @@ func resourceOracleDatabaseCloudVmClusterImport(d *schema.ResourceData, meta int
}
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 @@ -36,6 +36,7 @@ func TestAccOracleDatabaseCloudVmCluster_oracledatabaseCloudVmclusterBasicExampl
context := map[string]interface{}{
"cloud_exadata_infrastructure_id": "ofake-exadata-for-vm-basic",
"cloud_vm_cluster_id": "ofake-vmcluster-basic",
"deletion_protection": false,
"project": "oci-terraform-testing",
"random_suffix": acctest.RandString(t, 10),
}
Expand All @@ -52,7 +53,7 @@ func TestAccOracleDatabaseCloudVmCluster_oracledatabaseCloudVmclusterBasicExampl
ResourceName: "google_oracle_database_cloud_vm_cluster.my_vmcluster",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"cloud_vm_cluster_id", "labels", "location", "properties.0.gi_version", "properties.0.hostname_prefix", "terraform_labels"},
ImportStateVerifyIgnore: []string{"cloud_vm_cluster_id", "deletion_protection", "labels", "location", "properties.0.gi_version", "properties.0.hostname_prefix", "terraform_labels"},
},
},
})
Expand All @@ -76,6 +77,8 @@ resource "google_oracle_database_cloud_vm_cluster" "my_vmcluster"{
gi_version = "19.0.0.0"
hostname_prefix = "hostname1"
}
deletion_protection = "%{deletion_protection}"
}
resource "google_oracle_database_cloud_exadata_infrastructure" "cloudExadataInfrastructures"{
Expand Down Expand Up @@ -103,6 +106,7 @@ func TestAccOracleDatabaseCloudVmCluster_oracledatabaseCloudVmclusterFullExample
context := map[string]interface{}{
"cloud_exadata_infrastructure_id": "ofake-exadata-for-vm-full",
"cloud_vm_cluster_id": "ofake-vmcluster-full",
"deletion_protection": false,
"project": "oci-terraform-testing",
"random_suffix": acctest.RandString(t, 10),
}
Expand All @@ -119,7 +123,7 @@ func TestAccOracleDatabaseCloudVmCluster_oracledatabaseCloudVmclusterFullExample
ResourceName: "google_oracle_database_cloud_vm_cluster.my_vmcluster",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"cloud_vm_cluster_id", "labels", "location", "properties.0.gi_version", "properties.0.hostname_prefix", "terraform_labels"},
ImportStateVerifyIgnore: []string{"cloud_vm_cluster_id", "deletion_protection", "labels", "location", "properties.0.gi_version", "properties.0.hostname_prefix", "terraform_labels"},
},
},
})
Expand Down Expand Up @@ -164,6 +168,8 @@ resource "google_oracle_database_cloud_vm_cluster" "my_vmcluster"{
}
memory_size_gb = 60
}
deletion_protection = "%{deletion_protection}"
}
resource "google_oracle_database_cloud_exadata_infrastructure" "cloudExadataInfrastructures"{
Expand Down

This file was deleted.

5 changes: 5 additions & 0 deletions website/docs/r/oracle_database_cloud_vm_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ resource "google_oracle_database_cloud_vm_cluster" "my_vmcluster"{
gi_version = "19.0.0.0"
hostname_prefix = "hostname1"
}
deletion_protection = "true"
}
resource "google_oracle_database_cloud_exadata_infrastructure" "cloudExadataInfrastructures"{
Expand Down Expand Up @@ -118,6 +120,8 @@ resource "google_oracle_database_cloud_vm_cluster" "my_vmcluster"{
}
memory_size_gb = 60
}
deletion_protection = "true"
}
resource "google_oracle_database_cloud_exadata_infrastructure" "cloudExadataInfrastructures"{
Expand Down Expand Up @@ -201,6 +205,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.

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

Expand Down

0 comments on commit 132e7b4

Please sign in to comment.