Separate Discovery Support from Provider Runtime Support
Discovery answers a narrower question than the provider does. Resource discovery enumerates a compartment and writes HCL plus a state file. The provider's job is to plan, import and apply a declared object. A type can appear on one list and be missing from the other.
Two discovery surfaces exist, and they do not share a build. Resource Manager's stack-from-compartment runs the service-side exporter. The provider CLI export runs the exporter shipped with the provider binary. Check the supported list for the surface you will actually use.
The supported list is per service and per resource. A service can be supported while one of its resources is not, and the list belongs to a specific build. The provider CLI can print both lists with list_export_services and list_export_resources, which is the only honest comparison with what you run.
Authentication is not one path either. The provider CLI export supports API key and instance principal. A Resource Manager job is authorized through IAM for the caller and for every resource the job reads. Neither path grants the write access that the later apply needs.
Runtime support is a schema plus a pinned build. Terraform 1.17.1 with oracle/oci 9.12.1 can manage types that discovery never emits, and it can reject HCL generated for an older schema. Pin both before you judge an export.
The adoptable set is an intersection. On the export list, readable by the discovery principal, and manageable by the pinned provider. Everything outside it is either absent and must be recorded, or present and must not be owned.
The export is a snapshot, and the runtime build moves. Discovery reads at one moment with one build; your provider is upgraded on a different schedule. An object that was manageable at export time can gain a required argument or a new computed field before your import runs. The import plan, not the export, is the compatibility test.
Scope changes the answer at the root. A non-root compartment export stays at compartment level. The root compartment raises scope to the tenancy, where identity objects appear and need a different reviewer.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["Compartment snapshot"] --> B{"Which discovery surface?"}
B -->|"Resource Manager stack"| C["Service-side exporter"]
B -->|"provider CLI export"| D["Provider binary exporter"]
C --> E["Generated HCL and state"]
D --> E
E --> F{"Type on that build's
export list?"}
F -->|"no"| F1["Absent: record the omission"]
F -->|"yes"| G{"Readable by the
discovery principal?"}
G -->|"no"| G1["Absent or job failure
record the cause"]
G -->|"yes"| H["Object present in state"]
H --> I{"Pinned provider
can manage it?"}
I -->|"no"| I1["Stop: upgrade or leave external"]
I -->|"yes"| J["Eligible for adoption review"]
F1 --> K["Exclusion record"]
G1 --> K
I1 --> K
J --> L["Bounded import plan"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class A,E,L primary;
class B,F,G,I secondary;
class C,D,H,J ok;
class F1,G1,I1 danger;
class K warn;
Figure 1 orders the gates. A failure at the first one is not a provider problem, and installing a newer provider will not fix it.
The table separates the two contracts that people merge in conversation.
| Question | Discovery export | Provider runtime |
|---|---|---|
| Reader | service or CLI exporter, one compartment | provider refresh, one declared object |
| Supported set | per-service export list for that build | provider schema and resource docs |
| Version anchor | exporter build and target syntax | Terraform 1.17.1 and oracle/oci 9.12.1 |
| Authentication | API key or instance principal; IAM for a job | API key, security token, instance or resource principal |
| Output | HCL and a generated state file | plan, apply and refreshed state |
| Proves | the object exists and is readable | the object can be imported and changed |
| Typical failure | omission or a failed job | schema error, not found, conflict |
Scope the Compartment and Existing State Owners
The compartment is the discovery boundary, not the ownership boundary. A stack created from a compartment covers its supported resources at that scope. Child compartments are not walked, so a parent export is not an inventory of everything beneath it.
Every candidate OCID needs a negative check against every existing state. An import block does not consult other state files. Importing an object that another root already records succeeds and creates a second declarer; the duplicate stays invisible until one apply reverses the other.
Shared infrastructure is the first exclusion class. A VCN, subnet, route table, NSG, DRG, vault key, policy or compartment usually outlives one workload. Adopting it hands the workload root the power to change or delete a boundary other teams depend on.
Identity and guardrails are the second. A root-compartment export can contain users, groups, policies and dynamic groups. A workload root that owns them can rewrite its own access, which is a larger change than the workload it was meant to manage.
Data-bearing resources are the third. A volume, file system, database or bucket can be imported safely, but a later replacement destroys data. Adopt only with a restore rehearsal and prevent_destroy, or keep it external.
An owner outside Terraform still owns the object. A console-created bucket or a script-maintained policy has an owner even when no state records it. The ledger must name that person or team and get a decision, because importing the object transfers the ability to change it without asking.
Generated state claims more than the HCL you keep. The state records every discovered object, so deleting unwanted blocks does not shrink the claim. If the stack is retained, its state still declares the whole compartment.
Write the ledger before the import. One row per OCID: final address, type, compartment, current owner, decision, reason and reviewer. An object without a row is not approved, and an owner who cannot be found is a stop rather than a free object.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["One compartment export"] --> B{"Child compartments
in scope?"}
B -->|"yes"| B1["Parent export is incomplete
one pass per child"] --> C
B -->|"no"| C["Candidate OCIDs
from the export"]
C --> D{"OCID in any
existing state?"}
D -->|"yes"| D1["Exclude: already owned"] --> L
D -->|"not checked"| D2["Query every root first"] --> D
D -->|"no"| E{"Shared boundary?
VCN, subnet, key, policy"}
E -->|"yes"| E1["Exclude: reference by
data source or variable"] --> L
E -->|"no"| F{"Identity or guardrail?"}
F -->|"yes"| F1["Exclude: separate
identity root"] --> L
F -->|"no"| G{"Data-bearing?"}
G -->|"yes"| G1["Adopt only with restore
proof and prevent_destroy"] --> H
G -->|"no"| H["Bounded candidate set"]
H --> I{"Owner signs the ledger?"}
I -->|"no"| I1["Stop: no adoption"] --> L
I -->|"yes"| J["Freeze addresses
and exclusions"]
L["Exclusion record
reason and owner"] --> J
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class A,J primary;
class B,C,D,E,F,G,I secondary;
class H ok;
class D1,E1,F1,I1 danger;
class B1,D2,G1,L warn;
Figure 2 shows the exclusion branches. Each one ends in a written record rather than a verbal exception.
Review Generated IDs, Dependencies and Sensitive Values
Generated HCL is a transcript of API values, not a design. Names follow display names, identifiers are literals, blocks are inline, and relationships are written as OCID strings. The file is readable; it is not yet maintainable.
A literal OCID is not a reference. Terraform cannot order a graph or cascade a replacement through a string. If a subnet and its VCN are both adopted but linked by literals, a replace or destroy can run in the wrong order.
Open the availability-domain file too. Boot volumes, file systems, mount targets and snapshots are generated separately. A reviewer who reads only the main file approves a resource set that is not the one on disk.
Computed values belong to the service. OCIDs, timestamps, lifecycle states, etags, default route table and security list IDs, and system tags are read-only. Copying one from state into configuration produces a schema error or a permanent diff; leave it out.
Defaulted values are a decision inherited by accident. The API returns the effective value of an unset optional field, and the exporter writes it as a literal. Keeping it pins today's default; dropping it returns the choice to the service. Record which one you made.
A create-only argument needs a replacement review. Some values are accepted only at creation and read back afterwards, and the exporter writes the read-back value into configuration. If the provider marks that argument as create-only, a later edit proposes a replacement rather than an update. Check the replacement rule for every field you keep.
Placeholders are explicit debt. When a required attribute cannot be discovered, the export writes a placeholder and adds the field to ignore_changes so the first plan passes. That rule also hides every later change; replace the value or record the exclusion, then remove the rule.
Secrets are the part that cannot be exported. Passwords, private keys and tokens are masked or omitted, so the file may carry a placeholder instead. The state is plaintext JSON, and job-read permission exposes it; treat the download as a credential.
Rebuild dependencies rather than trusting them. Rewrite internal literals as references, keep external ones as variables or data sources, and add explicit ordering only where no reference exists. The next plan then shows a cascade before it runs.
Figure 3 separates what the export contains from what your configuration may own. The gap between the two panels is the review.
Import a Bounded Set and Reach a No-Change Baseline
The import unit is one reviewed address, not a compartment. Ten to twenty objects, one owner, no data-bearing resource whose replacement loses state, and a reviewer who can read the whole plan. A larger set produces a plan nobody reads and a rollback nobody can run.
Write the final address before the block. The module path and resource name decide the address, and changing either later is a state move. Put the OCID in the import block only after that address is frozen.
The first plan has two jobs. It must prove the import and prove no mutation. Terraform can import an object and then apply an update in the same run when the configuration differs, so read the plan for an update or replacement on the same address.
A create for an object you expected to import is a stop signal. The address, region or provider build is wrong. Importing at the wrong address does not fail; it records the right object under the wrong name, and a later apply can create a duplicate.
Apply the reviewed plan, then remove the import block. The import writes state and changes nothing on the OCI side. The next plan, after the block is gone, is the baseline; it should be empty except for named exclusions.
Prove the duplicate claim outside Terraform. For each adopted OCID, check every other root and the API inventory. The count for that resource family should equal the union of all roots' addresses plus the recorded external set.
A duplicate import succeeds, which is why the check cannot be a Terraform command. Terraform has no registry of other state files, so a second root can import the same OCID and both plans will look valid. Run the negative test in a throwaway root: import one adopted OCID, observe the success, then remove it. The guard has to be the ledger and the sweep, not the tool.
The baseline is bounded by the addresses you adopted. Objects left in the compartment stay unmanaged and will not appear in the plan at all. That is the intended result, not an omission: the exclusion record is the only place they are visible, and a later discovery run is how you check that the set has not drifted.
Freeze the evidence with coordinates. Plan job identifier, commit, state serial, provider version, Terraform version and object count. A clean plan without those coordinates is a screenshot, not an adoption record.
Figure 4 shows the three outcomes of the first plan. Only one of them is an import, and only that one is safe to apply.
Accept Adoption with a Recovery and Exclusion Record
Acceptance is a signed record, not an empty plan. The empty plan proves configuration matches reality at one moment. The record names the owner of each address, the objects left external, and the way back.
Recovery is asymmetric. A bad import is reversible by removing the address from state, because no API call changed the object. A bad apply is not; it may have changed or destroyed the object, and recovery is a restore or a recreate.
The recovery record is written before the first apply, not after the failure. It names the state address, the exact object, the last known backup or snapshot, and the identity that can restore it. Without that, removing an address from state is advice rather than a procedure.
The exclusion record stops the next discovery from reopening the same argument. Each external object gets a reason, an owner and the reference the configuration uses. Unsupported, shared, identity, data-bearing and already-owned cover the usual cases.
Do not call the result a migration. Discovery does not move a resource, change a region, rewrite an application endpoint or copy data. It produces a description; adoption is a state decision; migration is a separate project with a cutover.
The record has a review date. Exports age as objects change and the provider moves. Re-run discovery to compare with the record, not to overwrite the adopted root.
Accept Adoption with a Recovery and Exclusion Record
Status: design-only. This trace was written against Terraform 1.17.1 and oracle/oci 9.12.1 on 6 November 2026. No tenancy was queried and no resource was imported, so every expected result below is documented behaviour rather than a measurement.
Prerequisites. One sandbox compartment with a VCN, two subnets, one instance and one bucket, a Resource Manager stack created from that compartment, a separate read principal for discovery and a write principal for adoption, and an empty new root with a remote backend. Keep every identifier as a placeholder.
- Freeze the sandbox, record the inventory, and pin Terraform 1.17.1 with
oracle/oci9.12.1 in the new root. - Create the discovery stack, download the HCL and state, checksum both, and record the job identifier.
- Match the address count to the inventory. Write one line for every omission, including the child compartment you deliberately left out.
- Select eight to twelve objects. Exclude one shared subnet and one identity policy on purpose, and write both reasons in the ledger.
- Write canonical configuration at the final addresses. Replace internal literals with references, external IDs with variables, and list every
ignore_changesyou keep. - Add import blocks and plan. Expect an import with no update or replacement on those addresses; a create means the address or region is wrong.
- Apply the reviewed plan job, remove the import blocks, and plan again. Expect an empty baseline apart from the named exclusions.
- Sweep every other root for the adopted OCIDs. Each OCID must appear once, and the API count must equal the union of all roots plus the exclusions.
- Destroy through the new root, confirm the plan is empty, release any public IP, delete the test stack, and keep the evidence set.
| Check | Passing result | Failing result means |
|---|---|---|
| Export count | every expected object has a row | unsupported, unreadable, inactive or nested |
| Address freeze | one final address per OCID | two roots can claim the object |
| Import plan | import only, no update or replace | configuration disagrees with reality |
| Baseline plan | empty except named exclusions | ownership or dependency gap |
| Duplicate sweep | one state record per OCID | a second declarer exists |
Expected observation. Step 3 produces a short classified list rather than a wall of creates. Step 6 imports without changing the objects, and step 7 leaves only the exclusions. Step 8 returns one record for every adopted OCID, and step 9 removes the sandbox without touching a shared boundary.
Failure check. If step 6 shows an update on the same address, stop: applying it would change the live object and the import would no longer be state-only. If step 7 proposes a create, the state and configuration use different addresses. If step 8 finds the same OCID twice, one root must give it up before either applies.
Cost and cleanup. The lab bills for the instance, the bucket and any reserved public IP until step 9. Destroy through the root, confirm the plan is empty, then delete the discovery stack and its generated state copy. Deleting a stack does not delete resources, so destroy first.
Evidence to keep. The export checksum, the omission list, the ledger, the import plan, the baseline plan, the duplicate sweep and the destroy confirmation. Sanitize OCIDs, IP addresses and any secret before sharing.
Sources. Discovery scope, placeholders and the availability-domain file follow Oracle's Resource Discovery guide. Export flags and the supported-resource lists follow the oracle/oci resource discovery guide.