From 4f35372cac906449e109977c88bad2beea4fd8ed Mon Sep 17 00:00:00 2001 From: tulika-aakriti Date: Tue, 19 Nov 2024 22:33:46 +0530 Subject: [PATCH] Add deletion_protection field in cloudvmcluster resource (#12297) --- .../products/oracledatabase/CloudVmCluster.yaml | 17 +++++++++++++++++ ...oracledatabase_cloud_vmcluster_basic.tf.tmpl | 2 ++ .../oracledatabase_cloud_vmcluster_full.tf.tmpl | 2 ++ .../oracledatabase_cloud_vmcluster.go.tmpl | 3 +++ 4 files changed, 24 insertions(+) create mode 100644 mmv1/templates/terraform/pre_delete/oracledatabase_cloud_vmcluster.go.tmpl diff --git a/mmv1/products/oracledatabase/CloudVmCluster.yaml b/mmv1/products/oracledatabase/CloudVmCluster.yaml index ddc28f039c1e..e61c3e55295c 100644 --- a/mmv1/products/oracledatabase/CloudVmCluster.yaml +++ b/mmv1/products/oracledatabase/CloudVmCluster.yaml @@ -49,6 +49,8 @@ async: error: path: 'error' message: 'message' +custom_code: + pre_delete: 'templates/terraform/pre_delete/oracledatabase_cloud_vmcluster.go.tmpl' examples: - name: 'oracledatabase_cloud_vmcluster_basic' primary_resource_id: 'my_vmcluster' @@ -56,7 +58,11 @@ examples: project: 'my-project' cloud_vm_cluster_id: 'my-instance' cloud_exadata_infrastructure_id: 'my-exadata' + deletion_protection: 'true' + ignore_read_extra: + - 'deletion_protection' test_vars_overrides: + 'deletion_protection': 'false' 'project': '"oci-terraform-testing"' 'cloud_vm_cluster_id': '"ofake-vmcluster-basic"' 'cloud_exadata_infrastructure_id': '"ofake-exadata-for-vm-basic"' @@ -66,10 +72,21 @@ examples: project: 'my-project' cloud_vm_cluster_id: 'my-instance' cloud_exadata_infrastructure_id: 'my-exadata' + deletion_protection: 'true' + ignore_read_extra: + - 'deletion_protection' test_vars_overrides: + 'deletion_protection': 'false' 'project': '"oci-terraform-testing"' 'cloud_vm_cluster_id': '"ofake-vmcluster-full"' 'cloud_exadata_infrastructure_id': '"ofake-exadata-for-vm-full"' +virtual_fields: + - name: 'deletion_protection' + type: Boolean + default_value: 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.' parameters: - name: 'location' type: String diff --git a/mmv1/templates/terraform/examples/oracledatabase_cloud_vmcluster_basic.tf.tmpl b/mmv1/templates/terraform/examples/oracledatabase_cloud_vmcluster_basic.tf.tmpl index bef49b1943e8..7ac2edfa9301 100644 --- a/mmv1/templates/terraform/examples/oracledatabase_cloud_vmcluster_basic.tf.tmpl +++ b/mmv1/templates/terraform/examples/oracledatabase_cloud_vmcluster_basic.tf.tmpl @@ -14,6 +14,8 @@ resource "google_oracle_database_cloud_vm_cluster" "{{$.PrimaryResourceId}}"{ gi_version = "19.0.0.0" hostname_prefix = "hostname1" } + + deletion_protection = "{{index $.Vars "deletion_protection"}}" } resource "google_oracle_database_cloud_exadata_infrastructure" "cloudExadataInfrastructures"{ diff --git a/mmv1/templates/terraform/examples/oracledatabase_cloud_vmcluster_full.tf.tmpl b/mmv1/templates/terraform/examples/oracledatabase_cloud_vmcluster_full.tf.tmpl index e33babc91b9d..3cfe225f6454 100644 --- a/mmv1/templates/terraform/examples/oracledatabase_cloud_vmcluster_full.tf.tmpl +++ b/mmv1/templates/terraform/examples/oracledatabase_cloud_vmcluster_full.tf.tmpl @@ -35,6 +35,8 @@ resource "google_oracle_database_cloud_vm_cluster" "{{$.PrimaryResourceId}}"{ } memory_size_gb = 60 } + + deletion_protection = "{{index $.Vars "deletion_protection"}}" } resource "google_oracle_database_cloud_exadata_infrastructure" "cloudExadataInfrastructures"{ diff --git a/mmv1/templates/terraform/pre_delete/oracledatabase_cloud_vmcluster.go.tmpl b/mmv1/templates/terraform/pre_delete/oracledatabase_cloud_vmcluster.go.tmpl new file mode 100644 index 000000000000..3e00631873ad --- /dev/null +++ b/mmv1/templates/terraform/pre_delete/oracledatabase_cloud_vmcluster.go.tmpl @@ -0,0 +1,3 @@ +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()) +}