Choose Resource Manager or an Explicit CI Execution Owner
Resource Manager is an execution owner, not a configuration format. The HCL is the same HCL a laptop would run. A stack adds a compartment, a region, a pinned Terraform version, variables, state and a job history that outlives the engineer who clicked Apply.
One stack holds one configuration and one state. Only one job runs on a stack at a time, and a stack represents one set of resources. A second, unrelated workload needs a second stack, not another set of resources in the same one.
The word stack collides with two other products. An OCI stack is not a CloudFormation stack and not a Terraform Stack. Terraform Stacks orchestrates components and deployments in HCP Terraform, while an OCI stack is one configuration plus its state. Say which one you mean in the design note.
Resource Manager earns its place when OCI-native custody matters. State stays inside the service, job history hangs off the stack, drift detection is a job, and an apply can reference a specific plan job. IAM can grant stack and job rights without granting access to a state bucket.
CI earns its place when approval and tests already live there. A pipeline can run policy tests, provider schema checks and a saved-plan gate that Resource Manager does not provide. It can also span clouds and providers in one graph.
Two execution owners on one state is the failure mode. Both plans look clean because each compares against its own record, and each apply quietly reverses the other. There is no merge: the last writer wins, and the next diff has no clear cause.
The state decides the boundary, not the plan. Plans are cheap to regenerate; state lineage is not. Moving a root between owners needs a zero-writer window, a state transfer and a recorded serial.
%%{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 configuration
one resource set"] --> B{"Who owns the state?"}
B -->|"OCI-native custody"| C["Resource Manager stack"]
B -->|"pipeline artifact and tests"| D["CI runner with remote backend"]
B -->|"one engineer, short-lived"| E["Local state, never shared"]
C --> F{"Must the plan bind to approval?"}
F -->|"yes"| G["Plan job, then apply that job"]
F -->|"no"| H["Auto-approve only repeatable change"]
D --> I{"Saved plan reviewed?"}
I -->|"yes"| J["Apply the saved artifact"]
I -->|"no"| K["Re-plan after approval: a new change"]
G --> L["Record one state owner"]
J --> L
H --> L
E --> M["Retire before shared use"]
L --> N{"Second writer exists?"}
N -->|"yes"| O["Stop: zero-writer window first"]
N -->|"no"| P["Proceed to discovery or import"]
M --> P
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,L primary;
class B,F,I,N secondary;
class C,D,G,J,P ok;
class E,H,K,M warn;
class O danger;
| Decision | Resource Manager stack | CI-owned root |
|---|---|---|
| Configuration source | Git, bucket, folder or zip; Git jobs record the commit | Git at a reviewed commit, usually with tests |
| State custody | Service-managed, one state per stack | Object Storage backend with one prefix per root |
| Concurrency | One job at a time, enforced by the stack | Lock table plus pipeline concurrency rules |
| Plan approval | Apply can reference the latest plan job | Saved plan file and hash approval |
| Credential surface | OCI IAM stack and job rights plus resource policies | Federated or instance principal in the runner |
| Drift signal | Drift detection job with per-resource status | Scheduled read-only plan |
| Best fit | OCI-only estate with OCI-native custody | Tests, policy checks and multi-provider graphs |
Discover a Compartment with Supported Resources and Credentials
Discovery answers what exists in a compartment, not what you should own. Resource Manager reads the compartment, generates HCL and a state file, and builds a stack whose state already records what it found. The output is evidence; keeping it is a separate, longer commitment.
Scope is the compartment, and nested compartments are not walked. A stack is created from a single compartment. Choosing the root compartment gives tenancy-level scope, including identity objects; choosing a narrow child gives only that child's resources. There is no per-resource picker in the job.
Supported resources are a per-service list, not the provider schema. The provider can manage a type that discovery does not support, and runtime support does not imply identical discovery support. Read the supported-resource list published with the service, not the provider index.
Read permission and write permission belong to different principals. The discovery caller needs read on each service plus stack and job rights; the apply principal needs write. Using a tenancy administrator for discovery hides every permission gap the later apply will meet.
Absence in the export has several causes. An unsupported type, a resource the caller cannot read, an inactive object and a nested compartment can all leave the object missing, or fail the job with a message that names none of them. The file cannot tell you which cause applied.
Availability-domain resources land in their own file. Boot volumes, file systems, mount targets and snapshots are generated under a separate file named for availability domains. A reviewer who opens only the main file misses a whole class of objects.
The result is a snapshot, not a feed. Objects created after the job are absent, and objects deleted since may still appear. Drift detection is the tool for change over time; discovery is a one-shot read.
%%{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["Choose one compartment"] --> B{"Nested compartments in scope?"}
B -->|"yes"| B1["One discovery stack per compartment"]
B -->|"no"| C["Check the supported-resource list"]
C --> D{"Type is supported?"}
D -->|"no"| D1["Omitted: reference it or leave external"]
D -->|"yes"| E["Grant read plus stack and job rights"]
E --> F["Create the stack from the compartment"]
F --> G{"Discovery job state?"}
G -->|"failed"| G1["Read logs: permission, limit, service error"]
G -->|"succeeded"| H["Download configuration and state"]
H --> I{"Address count matches inventory?"}
I -->|"no"| I1["Classify: unsupported, unreadable, inactive, nested"]
I -->|"yes"| J["Freeze the snapshot and record versions"]
J --> K["Decide: adopt, harvest or discard"]
B1 --> C
D1 --> J
G1 --> E
I1 --> 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,F,J primary;
class B,C,D,G,I,K secondary;
class E,H,B1 ok;
class D1,I1 warn;
class G1 danger;
A discovery run is finished when the omissions are named. Count the objects you expected, count the addresses you received, and write one line for every difference. An unexplained difference is a reason to stop, not a reason to run discovery again.
Treat Generated Configuration as an Adoption Starting Point
Generated configuration describes the API, not your conventions. Names follow display names, values are literals, and blocks are inline. There are no variables, modules, ownership tags or environment splits unless the live object already carried them.
A clean plan after discovery proves internal consistency, not correctness. The configuration and the state were generated from the same read, so they agree by construction. Agreement says nothing about whether you should own the objects or whether the export is complete.
Oracle calls discovery a starting point, not a migration tool. The documentation is explicit that cloning or migrating resources requires changes. Treat the output as a draft with a known defect list, not as a release artifact.
Placeholders are debt, not a baseline. A placeholder satisfies validation, and an ignore rule hides the field from every future plan. Replace it with a real value or record why the field stays unmanaged.
Keeping the generated state claims the whole compartment. The state records every discovered object, so the stack becomes a declarer for all of them, including objects another team owns. The HCL is editable; that claim is the expensive part.
Adopt the compartment when the stack is meant to own all of it. This fits a rebuild into a new tenancy or region, or a compartment created for one service. Rename the stack, pin versions, and expect the first cleanup to be a large but explainable diff.
Harvest a bounded set when an existing root should own only part. Copy the blocks you need, rewrite addresses to the module convention, add import blocks, and leave the generated state behind. This is the common path for a running platform.
Discard the export when ownership is shared or unclear. Reading generated HCL is a good way to learn how OCI represents an object; keeping its state is a commitment you cannot make on another team's behalf. Delete the stack after the reading.
Normalize before the first apply. Externalize variables, remove literal secrets, add prevent_destroy to data-bearing resources, split identity and guardrails out, and attach ownership tags. Then plan and read the diff as a review, not a formality.
Identity is the export you should almost never apply. Root-compartment discovery can include users, groups, policies and dynamic groups. Applying those from a workload stack gives the workload a route to rewrite access, which is a larger change than the one under review.
Import and Upgrade with Protected State and Plans
Two operations share the word import. A Resource Manager import job uploads a state file and makes it the stack's current state, which is how a local root moves into the service. A Terraform import block adopts one resource during a plan. Confusing them yields an empty plan over unmanaged objects or a duplicate create.
Record four coordinates before the first job. The Terraform version (1.17.1 here), the exact provider constraint (oracle/oci 9.12.1), the configuration commit, and the variable values used by the job. A Git-backed stack records the commit on the job, which ties a plan to a review.
Pin the provider exactly for the adoption window. Resource Manager manages the dependency lock file and can retrieve newer providers within your constraints, so a range resolves to a different binary at the next job. Use an exact constraint while importing, then widen it deliberately.
Write the import block at the final address. Decide the module path and resource name first, put the canonical OCID in the block, and run a plan job. The plan must say the object will be imported and must not propose a replacement.
Apply that plan job, then remove the block. An apply job can reference the latest generated plan job, and that reference is the approval mechanism. After the import lands, delete the import block and plan again, because the next diff is the real baseline.
Bound the set to what one reviewer can read. Ten to twenty objects in one compartment, no data-bearing resource whose replacement loses state, and one owner per object. An account-wide import produces a plan nobody reads and a rollback nobody can run.
Only the latest plan job is available to an apply. A second plan supersedes the first, so a stack with two planners has no stable approval artifact. Freeze plan jobs during approval, and treat a variable edit as a new change rather than a correction.
Auto-approve is the wrong default for adoption. It plans and applies in one job, so nobody reads the import or replacement diff. Reserve it for repeatable changes that have already survived a referenced plan.
Job read access is state read access. The job read permission exposes state files and configurations, and state can contain sensitive values. Keep stacks in a compartment with a narrow reader group, and do not grant job read to everyone who can open the console.
A secret in a variable is stored with the job. Variables appear in job details, and configuration is downloadable through the job API. Keep credentials in Vault and reference them at runtime; a private key in a variable is a leaked key with a job OCID attached.
Migrating a local root is a transfer, not an adoption. Stop local writers, back up state and lock file, create the stack at the same versions, run the import state job, then plan with refresh. Creates for objects that exist mean the state came from different addresses.
A failed import is cheaper than a duplicate create. Import writes state and never touches the account. A replacement after import is a stop signal: the block and the live object disagree about an immutable field, and applying would destroy the object you just adopted.
The transfer is complete when a fresh plan is empty and the old writer is gone. An empty plan from the new owner is necessary but not sufficient; the old pipeline must also be disabled, or the next scheduled run reintroduces the second declarer.
Recover a Failed Job and Reconcile Remote Reality
A failed job is a normal outcome with a partial record. Terraform stops at the first error and records the resources completed before it, while the failing object is absent or tainted. The downloadable state follows the last successful job, so the record can sit behind reality.
Never re-run the failed apply or reuse its plan. Run a new plan and read what it proposes for the addresses that did land. A create against an object that already exists is an import candidate, not a retry.
Diagnose the layer before touching state. An expired session, a missing policy, a service limit, exhausted capacity, a name collision, a provider defect and a timeout all stop the same graph. The job log names the layer; the plan summary does not.
A running job is the lock. One job at a time per stack means an in-progress job blocks every other job, including the plan you need. Cancel it, wait for canceled, then investigate; do not delete the stack to clear it.
Deleting a stack is the worst recovery move. The resources persist and the state is deleted, which turns a recoverable partial apply into an estate you must rediscover. Delete a stack only after a destroy job and a confirmed empty plan.
Recover a lost state in a fixed order. Freeze writers, then find the newest artifact: the stack state from the last successful job, a job state from an apply, rollback or import, an exported copy, or a version in the old Object Storage backend. Only when all are gone does discovery become the source.
Discovery rebuilds evidence, not ownership. A fresh discovery stack can describe the compartment, but its addresses follow display names and it claims every object it finds. Use it to enumerate reality, then import a bounded set at your final addresses into the real root.
Rollback is a change, not a restore. A plan rollback and apply rollback converge the stack on an earlier successful apply job's state. Resources created since may be destroyed, so use it when that reversal is the intent, not to recover a file.
Classify every address in three buckets. Recorded and present is done; present but unrecorded is an import; recorded but absent is a recreate or a removed block. A tainted object is a replace decision, and a removed block without destroy drops the record without calling the API.
Recover a Failed Job and Reconcile Remote Reality
Status: design-only. No Oracle Cloud tenancy, credential or billable resource was used, and none of these steps ran. Every identifier is a placeholder.
Prerequisites. Terraform CLI 1.17.1, provider oracle/oci 9.12.1, one sandbox compartment with a console-created VCN, two subnets and one instance, a Git-backed stack, and separate read and apply principals.
- Record the stack's Terraform version, exact provider constraint and the commit shown on the first plan job.
- Run a plan job, download its log, and keep the job identifier as the approval artifact.
- Remove the apply principal's permission for one resource type, then apply. Record the failed state and the addresses that landed.
- Download the stack state and compare its serial and resource list with the compartment inventory.
- Restore the permission and plan with refresh. Classify each address as recorded and present, present and unrecorded, or recorded and absent.
- Import the unrecorded subnet at its final address, apply the referenced plan job, remove the block, and plan again.
- Create a second stack from the same branch, import the last good state file, and confirm an empty plan. Delete that test stack; its state is a copy.
- Force a second failure with an instance shape the compartment cannot host, then recover from a fresh plan.
- Run drift detection, change one tag by hand, and confirm the next detection names that address.
- Destroy through the stack, confirm an empty plan, and remove the test state file and temporary role.
| Address after the failure | State record | Compartment reality | Correct action |
|---|---|---|---|
| VCN | Recorded | Exists and unchanged | Leave it alone |
| First subnet | Recorded | Exists and unchanged | Leave it alone |
| Second subnet | Absent | Exists with a console name | Import at the planned address |
| Instance | Tainted or absent | Exists or partially created | Import, or replace deliberately |
| Reserved public IP | Absent | May exist and bill hourly | Assign an owner before deleting |
| Stack state | Last successful serial | Behind the failed apply | Plan from a fresh read |
Expected observation. Step 5 produces a short classified list, not a wall of creates. Step 6 leaves the subnet recorded and the plan empty apart from named exceptions, and step 9 names exactly the resource you edited.
Failure check. If step 6 proposes to create the VCN, the state came from different addresses or a region. If it destroys the subnet, the import address is not the one the configuration uses. If step 9 reports drift on everything, the stack is reading stale state.
Cost and cleanup. Destroy the workload through the stack, release any public IP or boot volume left behind, confirm an empty plan, then delete the test stack and state copy. Deleting a stack does not delete resources, so destroy first.