Oracle Cloud Infrastructure Documentation

Sample: Creating a Compute Instance Using Resource Manager

This sample provides an end-to-end walkthrough of the tasks required to create and deploy an Oracle Cloud Infrastructure Compute instance using the Oracle Resource Manager. For a brief introduction to Resource Manager, see Overview of Resource Manager.


Avoid entering confidential information when assigning descriptions, tags, or friendly names to your cloud resources through the Oracle Cloud Infrastructure Console, API, or CLI.


This walkthrough provides samples that demonstrate how to use Oracle Cloud Infrastructure Resource Manager to create a Compute instance. Resource Manager uses Terraform to provision the resources that you've defined in a Terraform configuration. The resources are organized into stacks, which you create and provision using jobs.

The walkthrough covers four general tasks:

  • Create a Terraform configuration using the HashiCorp configuration language (HCL). For more information, see Configuration Syntax.
  • Create a stack in which to provision your infrastructure.
  • Run a plan job against your stack, which parses your configuration and creates a Terraform execution plan.
  • Run an apply job, which uses the execution plan to provision the stack with the resources that you defined in the Terraform configuration.

Before We Begin

Ensure that you have installed, obtained, or created the prerequisites:

  • An Oracle Cloud Infrastructure tenancy
  • The Oracle cloud ID (OCID) for the compartment where you wish to create your stack.
  • A user account that includes the following:
  • If you wish to use the Oracle Cloud Infrastructure CLI instead of the Console, you will need to install and configure it. For details on setting up the CLI, see the Quickstart and Configuration

Create the Terraform Configuration


This section applies whether you are using either the Console or the command line interface (CLI).

A Terraform configuration is a set of files that define your Terraform provider, specify the resources you intend to provision, declare variables, and provide specific instructions for provisioning the resources. The configuration files are bundled into a .zip file and uploaded to Resource Manager. For more information, see Terraform Configuration.

In this example, our configuration uses several configurations (.tf) files to direct Resource Manager to execute the following sequence of operations:

Create an Oracle Cloud Infrastructure Provider
Define Variables
Create a Virtual Cloud Network (VCN)
Create a Subnet in Your VCN
Create an Internet Gateway
Create a Core Route Table
Create a Compute Instance
Finalize the Configuration

Build, Deploy, and Provision the Infrastructure

Use your Terraform configuration to build and deploy your infrastructure by taking the following actions:

  1. Create a stack in a tenancy compartment of your choosing.
  2. Run a plan job against the configuration. This creates and "execution plan," which is a step-by-step representation of the deployment in job log entries.
  3. Review the execution plan to confirm that it represents your intentions. If changes are needed, revise the configuration, then rerun the plan job to obtain an updated execution plan.
  4. Run an apply job against the execution plan. This provisions the stack that you created with the resources that you specified in your configuration.
  5. You can review the job's log entries. You also have access to Terraform state, which represents the current state of the deployment.

Create a Stack

Stacks are collections of resources that you can act on as a group. All of the resources that you specify in your configuration are provisioned in the stack that you create.

Create a Stack Using the Console
Create a Stack Using the CLI
Create, Edit, or Delete Variables Using the Console

Run a Plan Job

The plan job parses your configuration and creates an execution plan, but does not act on the stack. Once the plan job has completed, you can evaluate the execution plan by viewing the job's log entries to confirm that it performs the expected operations, and in the intended sequence.


To update the execution plan after running the plan job, you must first update the configuration and recreate the configuration .zip file. Then, upload the new .zip file and rerun the plan job.

Run a Plan Job Using the Console
Run a Plan Job Using the CLI

Run the Apply Job

When satisfied with the execution plan, we're ready to do the work of provisioning the stack with the resources that we've defined. The apply job takes the execution plan and "applies" it to the stack. The result is a fully provisioned stack.

Run the Apply Job Using the Console
Run the Apply Job Using the CLI

Review State

Essential information about the state of your resources configuration is maintained in a state file, which is a JSON file. The state file maps your stack's resources to your configuration and also maintains essential configuration metadata, such as resource dependencies. Resource Manager generates and updates state files automatically.

The Resource Manager supports state locking by allowing only one job at a time to run on a given stack. For more information about state files, see Hashicorp: State.

Review State Using the Console
Review State Using the CLI

About Destroy Jobs

If necessary, you can tear down the stack you created and clean up the resource that it contains by running a destroy job.

Run a Destroy Job Using the Console
Run a Destroy Job Using the CLI