oracle / terraform-provider-oci

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

Import oci_database_db_system that was launched as clone or from backup (backup_id != null or source_db_system_id != null) triggers replace #1470

Closed jeliker closed 1 year ago

jeliker commented 3 years ago

Community Note

Terraform Version and Provider Version

Terraform v1.0.9
on darwin_amd64
+ provider registry.terraform.io/hashicorp/oci v4.48.0

Affected Resource(s)

resource "oci_database_db_system" "db_from_backup" {
  #Required
  availability_domain = var.availability_domain
  compartment_id      = var.compartment_id
  db_home {
    #Required
    database {
      #Required
      admin_password = var.admin_password

      #Optional
      backup_id           = var.backup_id
      backup_tde_password = var.backup_tde_password
    }
  }
  hostname        = var.hostname
  shape           = var.shape
  ssh_public_keys = var.ssh_public_keys
  subnet_id       = var.subnet_id

  #Optional
  source = "DB_BACKUP"
}

Apply/create above which may timeout if > 2hrs. Following, I use

terraform import oci_database_db_system.db_from_backup NEW_OCID_FOR_DB

…then follow with terraform plan

  # oci_database_db_system.db_from_backup must be replaced
-/+ resource "oci_database_db_system" "db_from_backup" {
      + backup_subnet_id                        = (known after apply)
      + cluster_name                            = (known after apply)
      ~ cpu_core_count                          = 8 -> (known after apply)
. . .
      ~ source                                  = "NONE" -> "DB_BACKUP" # forces replacement
. . .
}

…or…

resource "oci_database_db_system" "db_from_system" {
  #Required
  availability_domain = var.availability_domain
  compartment_id      = var.compartment_id
  db_home {
    #Required
    database {
      #Required
      admin_password = var.admin_password
    }
  }
  hostname        = var.hostname
  shape           = var.shape
  ssh_public_keys = var.ssh_public_keys
  subnet_id       = var.subnet_id

  #Optional
  source              = "DB_SYSTEM"
  source_db_system_id = var.db_system_id
}

…then follow with terraform plan

  # oci_database_db_system.db_from_system must be replaced
-/+ resource "oci_database_db_system" "db_from_system" {
      + backup_subnet_id                        = (known after apply)
      + cluster_name                            = (known after apply)
      ~ cpu_core_count                          = 8 -> (known after apply)
. . .
      ~ source                                  = "NONE" -> "DB_SYSTEM" # forces replacement
. . .
}

Debug Output

Panic Output

Expected Behavior

Actual Behavior

Steps to Reproduce

See above

Important Factoids

References

jeliker commented 3 years ago

It seems the issue might be more a flaw in the import process which is not properly preserving source-db-system-id (for server built as clone) on the imported system. This seems like something that could be remedied in there Terraform provider (vs. API).

For servers built from DB backup I don't find any reference on the API page Database resource type that reflects the origin of the DB (i.e. OCID of a backup or OCID of another DB when building as clone). Perhaps this is an oversight at the API level?

ravinitp commented 1 year ago

We are very sorry that we couldn't respond to each and every issue reported on GitHub. Although we have refined the process to prioritize customer issues on GitHub, since this issue was reported a while ago, there is a good chance it may have been fixed in the latest version of Terraform Provider OCI. If you are still experiencing this issue, please create a new issue and label it as Bug.