Creating a Stack from an Existing Compartment
Using resource discovery, create a stack in Resource Manager based on an existing compartment to generate a Terraform configuration that describes the compartment's resources.
For more information about resource discovery, see Resource Discovery.
A work request runs on the stack. When the work request finishes, a job runs to generate a Terraform configuration file for the stack. When the job finishes, the resources in the selected compartment are captured in the generated configuration. You can recreate these resources in another compartment. To monitor the operation or investigate a failure, open the work request and view its logs. See Getting Logs for a Work Request and Getting Log Content for a Work Request.
Use the
oci resource-manager stack create-from-compartmentcommand and required parameters to create a stack from a compartment.oci resource-manager stack create-from-compartment --compartment-id <compartment_OCID> --config-source-compartment-id <source_compartment_OCID> --config-source-region <region>Example RequestFor example (discovers supported resources from the
coreanddatabaseservices; the source compartment is not a root compartment):oci resource-manager stack create-from-compartment --config-source-compartment-id ocid1.tenancy.oc1..uniqueid1 --config-source-region PHX --config-source-services-to-discover [core,database] –-compartment-id ocid1.tenancy.oc1..uniqueid2 --terraform-version 0.13.X --display-name "Stack From Compartment ABC" --description "List of Resources to Duplicate"Example Response{ "data": { "config-source": { "config-source-type": "COMPARTMENT_CONFIG_SOURCE" }, "defined-tags": {}, "display-name": "Stack from Compartment ABC", "freeform-tags": {}, "id": "ocid1.ormstack.oc1..uniqueid", "lifecycle-state": "CREATING", "time-created": "2019-04-03T18:26:56.299000+00:00", "variables": { "compartment_ocid": "ocid1.compartment.oc1..uniqueid1", "region": "us-phoenix-1" } } }{ "data": { "compartment-id": "ocid1.compartment.oc1..uniqueid2", "config-source": { "compartment-id": "ocid1.compartment.oc1..uniqueid1", "config-source-type": "COMPARTMENT_CONFIG_SOURCE", "region": "PHX", "working-directory": null }, "defined-tags": {}, "description": "List of Resources to Duplicate", "display-name": "Stack From Compartment ABC", "freeform-tags": {}, "id": "ocid1.ormstack.oc1.phx.uniqueid", "lifecycle-state": "CREATING", "stack-drift-status": "NOT_CHECKED", "terraform-version": "0.12.x", "time-created": "2020-06-01T18:25:56.102000+00:00", "time-drift-last-checked": null, "variables": {} }, "etag": "009010cb57f5162655c6a34f5ef8834f204a734df81e4baa696a7d830488ea25", "opc-work-request-id": "ocid1.ormworkrequest.oc1.phx.uniqueid" }Tip
Save theopc-work-request-idreturned by this asynchronous operation. Use it to retrieve work request details, error messages, log entries, or raw log content. See Getting Logs for a Work Request.For a complete list of parameters and values for CLI commands, see the Command Line Reference for Resource Manager.
Use the CreateStack operation to create a stack from a compartment.
For an example of the
configSourcepart of the request, see CreateCompartmentConfigSourceDetails.Tip
Use the work request OCID returned by the operation to retrieve log entries or raw log content. See Getting Logs for a Work Request.Example requestPOST /20180917/stacks Host: resourcemanager.us-phoenix-1.oraclecloud.com <authorization and other headers> { "compartmentId": "ocid1.compartment.oc1..<unique_ID>", "displayName": "My Compartment Configuration", "configSource": { "configSourceType": "COMPARTMENT_CONFIG_SOURCE", "compartmentId": "ocid1.compartment.oc1..<unique_ID>", "region": "us-phoenix-1" } }
What to Do Next
You can download the generated Terraform configuration file. You can also re-create infrastructure in another compartment.
Alternatively, you can view the generated Terraform configuration file in Code Editor. For more information, see Editing a Configuration Using Code Editor.