oracle / terraform-provider-oci

Terraform Oracle Cloud Infrastructure provider
https://www.terraform.io/docs/providers/oci/
Mozilla Public License 2.0
760 stars 683 forks source link

oci_database_autonomous_database failed to destroy primary/remote standby correctly. #1908

Open luckeyca opened 1 year ago

luckeyca commented 1 year ago

Community Note

Terraform Version and Provider Version

Terraform v1.4.5 on linux_amd64

Affected Resource(s)

oci_database_autonomous_database

Terraform Configuration Files

variable "autonomous_database_deploy" {
  type        = bool
  description = "(Required) Indicate whether to deploy the autonomous database instance"
  default     = false
}

variable "standby_autonomous_database_deploy" {
  type        = bool
  description = "(Required) Indicate whether to deploy the autonomous database instance"
  default     = false
}

resource "oci_database_autonomous_database" "primary" {
  count                               = var.autonomous_database_deploy ? 1 : 0
  compartment_id                      = "ocid1.compartment.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  db_name                             = "testadb1"
  display_name                        = "test autonomous database primary"
  is_free_tier                        = false
  db_workload                         = "DW"
  license_model                       = "LICENSE_INCLUDED"
  db_version                          = "19c"
  cpu_core_count                      = 1
  is_auto_scaling_enabled             = false
  data_storage_size_in_tbs            = 1
  is_auto_scaling_for_storage_enabled = false
  is_dedicated                        = false
  source                              = "NONE"
  whitelisted_ips                     = null
  subnet_id                           = "ocid1.subnet.oc1.xxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  nsg_ids                             = ["ocid1.networksecuritygroup.oc1.xxxxxxx.xxxxxxxxx"]
  admin_password                      = "Testpassword@213234"
}

resource "oci_database_autonomous_database" "standby" {
  count                               = var.standby_autonomous_database_deploy ? 1 : 0
  provider                            = oci.remote_region
  compartment_id                      = "ocid1.compartment.oc1..aaaaaaaaui5npqsoh4mqtvtwaj242sdlwg7gusw3ohdegizqzgjs6pzp75dq"
  db_name                             = "testadb1"
  display_name                        = "test autonomous database standby"
  is_free_tier                        = false
  db_workload                         = "DW"
  license_model                       = "LICENSE_INCLUDED"
  db_version                          = "19c"
  cpu_core_count                      = 1
  is_auto_scaling_enabled             = false
  data_storage_size_in_tbs            = 1
  is_auto_scaling_for_storage_enabled = false
  is_dedicated                        = false
  source                              = "CROSS_REGION_DATAGUARD" 
  source_id                           = oci_database_autonomous_database.primary[0].id
  whitelisted_ips                     = null
  subnet_id                           = "ocid1.subnet.oc1.xxxxx.xxxxxxxxxxxxxxxxxxxq"
  nsg_ids                             = ["ocid1.networksecuritygroup.oc1.xxxxx.xxxxxxxxxxxxxxxxxxq"]
}

Expected Behavior

When destroying the standby and primary database by switching the *_deploy from true to false, standby should be destroyed followed by primary.

Actual Behavior

standby was destroyed first correctly, then primary destroy process started and failed right away with error saying standby needs to be destroyed first. However, from both terraform results and from oci gui console, it indeed showed standby was already destroyed. error with opc request ID as below:

oci_database_autonomous_database.standby[0]: Destroying... [id=ocid1.autonomousdatabase.oc1.xxxxx.xxxxxxxxxxxxxxxxxxx]
....
....
oci_database_autonomous_database.standby[0]: Destruction complete after 3m3s
oci_database_autonomous_database.primary[0]: Destroying... [id=ocid1.autonomousdatabase.oc1.xxxxxx.xxxxxxxxxxxxxxxxxx]

│ Error: 400-InvalidParameter, Operation failed. Terminate the Cross-region Data Guard standby database first, and then retry terminating the primary database.
│ Suggestion: Please update the parameter(s) in the Terraform config as per error message Operation failed. Terminate the Cross-region Data Guard standby database first, and then retry terminating the primary database.
│ Documentation: https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/database_autonomous_database
│ API Reference: https://docs.oracle.com/iaas/api/#/en/database/20160918/AutonomousDatabase/DeleteAutonomousDatabase
│ Request Target: DELETE https://database.ca-toronto-1.oraclecloud.com/20160918/autonomousDatabases/ocid1.autonomousdatabase.oc1.xxxxx.xxxxxxxxxx
│ Provider version: 5.3.0, released on 2023-06-29.
│ Service: Database Autonomous
│ Operation Name: DeleteAutonomousDatabase
│ OPC request ID: c9edaaa2328e514a4f186f72e800853a/CAD988B63425243237F81E121D86F404/25AC26DBE42712E27E039DBE8642DA7C

Steps to Reproduce

  1. use the code snippet above to create primary with remote standby instances.
  2. once deployment completed, change the two *_deploy variable default from true to false to destroy the instances.
  3. terraform apply.

Important Factoids

References

kk-hiraskar commented 1 year ago

@luckeyca Added the reaction, and also commenting to say, facing same issue here, any solution you got for this ?

luckeyca commented 1 year ago

Hi @kk-hiraskar, I think for now the workaround is to set the deploy to false ONE-by-ONE to make sure standby is gone first, before set primary to deploy = false. This is very sad as adb development hasn't been really active on many of the reported terraform bugs.

luckeyca commented 8 months ago

@kk-hiraskar. It's been a while. for now, you can also time_sleep to add a delay destroy https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep. The permanent solution is to re-work the resource to make it more like terraform declarative. I have an enhancement request here: https://github.com/oracle/terraform-provider-oci/issues/2046 which oracle has an ER that is being active looked at and worked on from what I heard.