Recreating Infrastructure from an Existing Compartment

Using resource discovery in Resource Manager, re-create existing infrastructure from an existing compartment.

For more information about resource discovery, see Resource Discovery.

The following high-level instructions show how to re-create infrastructure from an existing compartment. To access detailed steps, click the provided links.

  1. Create a stack from the compartment that contains the resources you want to re-create.
  2. Download the generated Terraform configuration file.
  3. Edit the vars.tf file (variables in the downloaded Terraform configuration file) to specify the destination compartment_ocid and region.

    Example:

    variable "compartment_ocid" {
      default = "ocid1.compartment.oc1..uniqueid"
    }
    variable "region" {
      default = "us-phoenix-1"
    }
  4. If the destination region has more or fewer availability domains than the source region, then edit the vars.tf file to specify the correct number of availability domains.

    For example, if you cloned from a region that has 3 availability domains and you want to re-create the infrastructure in a region that has only 1 availability domain, then remove the references to the second and third availability domains.

    Example showing 3 availability domains:

    data oci_identity_availability_domain export_NzDH-EU-FRANKFURT-1-AD-1 {
      compartment_id = var.compartment_ocid
      ad_number      = "1"
    }
    data oci_identity_availability_domain export_NzDH-EU-FRANKFURT-1-AD-2 {
      compartment_id = var.compartment_ocid
      ad_number      = "2"
    }
    data oci_identity_availability_domain export_NzDH-EU-FRANKFURT-1-AD-3 {
      compartment_id = var.compartment_ocid
      ad_number      = "3"
    }

    Example showing 1 availability domain:

    data oci_identity_availability_domain export_NzDH-EU-FRANKFURT-1-AD-1 {
      compartment_id = var.compartment_ocid
      ad_number      = "1"
    }
  5. Store the edited configuration file in the location that you want to reference when creating the second stack.
    You can store a configuration file in a zip file, folder, Git repository, or other location supported by Resource Manager for creating stacks. See Where to Store Your Terraform Configurations.
  6. Create a second stack using the edited configuration file.
  7. (Optional) Run a plan job on the new stack.
  8. Run an apply job on the new stack.
The resources are cloned in the specified compartment and region.