Skip to content

oci_database_autonomous_database failed to destroy primary with refreshable clone correctly. #2487

@luckeyca

Description

@luckeyca

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version and Provider Version

Terraform v1.13.4
on linux_amd64

provider version: oracle/oci v7.26.1

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     = true
}

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

provider "oci" {
  region = "ca-toronto-1"
}

provider "oci" {
  alias  = "montreal"
  region = "ca-montreal-1"
}

terraform {
  required_version = ">= 1.8.5, < 2.0.0"

  required_providers {
    oci = {
      source                = "oracle/oci"
      version               = ">= 6.0.0, < 8.0.0"
      configuration_aliases = [oci.montreal]
    }
  }
}

resource "oci_database_autonomous_database" "primary" {
  count                               = var.autonomous_database_deploy ? 1 : 0
  compartment_id                      = "ocid1.compartment.oc1..aaaaaaaaui5npqsoh4mxxxxxxxxxxxxxxxxxxxxxxx"
  db_name                             = "testadb1"
  display_name                        = "test autonomous database primary"
  is_free_tier                        = false
  db_workload                         = "DW"
  license_model                       = "LICENSE_INCLUDED"
  db_version                          = "19c"
  compute_model                       = "ECPU"
  compute_count                       = 4
  # is_auto_scaling_enabled             = true
  data_storage_size_in_tbs            = 1
  is_auto_scaling_for_storage_enabled = true
  is_local_data_guard_enabled         = true
  is_dedicated                        = false
  source                              = "NONE"
  whitelisted_ips                     = null
  subnet_id                           = "ocid1.subnet.oc1.ca-toronto-1.aaaaaaaakfxyoexsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  nsg_ids                             = ["ocid1.networksecuritygroup.oc1.ca-toronto-1.aaaaaaaaru4b2nkvxxxxxxxxxxxxxxxxxxxxxxxxxxx"]
  admin_password                      = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

  database_management_status = "ENABLED"
  operations_insights_status = "ENABLED"
}

# workaround
resource "time_sleep" "on_destroy" {
  depends_on = [oci_database_autonomous_database.primary]

  destroy_duration = "3m"
}


resource "oci_database_autonomous_database" "clone" {
  count                               = var.standby_autonomous_database_deploy ? 1 : 0
  provider                            = oci.montreal
  compartment_id                      = "ocid1.compartment.oc1..aaaaaaaaui5nxxxxxxxxxxxxxxxxxxxxxxxx"
  db_name                             = "testadb1"
  display_name                        = "test autonomous database refreshable clone"
  is_free_tier                        = false
  db_workload                         = "DW"
  license_model                       = "LICENSE_INCLUDED"
  db_version                          = "19c"
  compute_model                       = "ECPU"
  compute_count                       = 4
  # is_auto_scaling_enabled             = true
  data_storage_size_in_tbs            = 1
  is_auto_scaling_for_storage_enabled = true
  is_dedicated                        = false
  source                              = "CLONE_TO_REFRESHABLE"
  refreshable_mode                    = "AUTOMATIC"
  auto_refresh_point_lag_in_seconds   = 0
  auto_refresh_frequency_in_seconds   = 3600
  time_of_auto_refresh_start          = "2025-11-20T01:00:00.000Z"
  source_id                           = oci_database_autonomous_database.primary[0].id
  whitelisted_ips                     = null
  subnet_id                           = "ocid1.subnet.oc1.ca-montreal-1.aaaaaaaaqjrunscpxxxxxxxxxxx"
  nsg_ids                             = ["ocid1.networksecuritygroup.oc1.ca-montreal-1.aaaaaaaauvdmwzrm3u66kfmntldcdqeex"]
  # admin_password                      = "xxxxxxxxxxxxxxxxxxxxxxxx"

  database_management_status = "ENABLED"
  operations_insights_status = "ENABLED"

# workaround
  depends_on = [time_sleep.on_destroy]
}

Debug Output

Panic Output

Expected Behavior

when running "terraform destroy", refreshable will be destroyed, followed by primary

Actual Behavior

refreshable clone was shown destroyed, however, destroying primary failed with error "Terminating an Autonomous AI Database is not permitted if the database has attached refreshable clones." see error below. This is similar problem as #1908 when destroying primary and remote standby. the same workaround using time_sleep resource works as shown in the code above.

oci_database_autonomous_database.clone[0]: Still destroying... [id=ocid1.autonomousdatabase.oc1.ca-montrea...6amn4geexwex73yv2bwe5ehtabnqcu5oehq6sa, 03m20s elapsed]
oci_database_autonomous_database.clone[0]: Still destroying... [id=ocid1.autonomousdatabase.oc1.ca-montrea...6amn4geexwex73yv2bwe5ehtabnqcu5oehq6sa, 03m30s elapsed]
oci_database_autonomous_database.clone[0]: Destruction complete after 3m31s
oci_database_autonomous_database.primary[0]: Destroying... [id=ocid1.autonomousdatabase.oc1.ca-toronto-1.an2g6ljr5xeuumqakeqpmpjv5rztibpub64gr45wdureiuzv3qynte4xxupa]

│ Error: 400-InvalidParameter, Terminating an Autonomous AI Database is not permitted if the database has attached refreshable clones. Detach or terminate any refreshable clones and try again.
│ Suggestion: Please update the parameter(s) in the Terraform config as per error message Terminating an Autonomous AI Database is not permitted if the database has attached refreshable clones. Detach or terminate any refreshable clones and try again.
│ 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.ca-toronto-1.an2g6ljr5xeuumqakeqpmpjv5rztibpub64gr45wdureiuzv3qynte4xxupa
│ Provider version: 7.26.1, released on 2025-11-13.
│ Service: Database Autonomous
│ Operation Name: DeleteAutonomousDatabase
│ OPC request ID: f3b503d5d192f1ce2b64017041bff823/965A8B881CB07B4909FA5DC68E587DC7/EE76FDD0177F54E4F40C84CD90A52417

Steps to Reproduce

  1. use the code example above and put in the real values
  2. terraform apply
  3. terraform destroy

Important Factoids

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-ProgressTerraform Team is working on the reproduce & fixbug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions