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 Resource Manager. For a brief introduction to Resource Manager, see Overview of Resource Manager.

Warning

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

Highlights

This walkthrough provides samples that demonstrate how to use 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 the following tasks:

  • Create a Terraform configuration using the HashiCorp configuration language (HCL). For more information, see Configuration Syntax.
  • Provision the infrastructure: 
    • Create a stack in which to provision your infrastructure.
    • Run a plan job against your stack, which parses your configuration and creates an execution plan.
    • Review the generated execution plan.
    • Run an apply job against your stack, which provisions your resources. The apply job follows the execution plan, which is based on your Terraform configuration.
    • Review the resulting infrastructure.

Before We Begin

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

  • An Oracle Cloud Infrastructure tenancy
  • The An Oracle-assigned unique ID called an Oracle Cloud Identifier (OCID). This ID is included as part of the resource's information in both the Console and API. for the compartment where you wish to create your stack.
  • A user account that includes the following:
  • If you want to use the Oracle Cloud Infrastructure CLI, install and configure the CLI first. See Quickstart and Configuration

Task 1: Create the Terraform Configuration

A Terraform configuration is a .zip file containing one or more files that codify your infrastructure. The configuration defines your Terraform provider, the resources you intend to provision, variables, and specific instructions for provisioning the resources. You need a Terraform configuration to get started with Resource Manager. For more information, see Terraform Configuration.

Warning

Do not provide user credentials or other confidential information in your Terraform configuration.

In this example, our configuration uses several configuration files (.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

Task 2: 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.

    A stack is a collection 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.

    To create a stack (Console)
    To create a stack (CLI)
  2. Generate an execution plan.

    The plan job parses your configuration to create an "execution plan," which is a step-by-step representation of the planned deployment in job log entries. 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 run a plan job (Console)
    To run a plan job (CLI)
  3. Review the execution plan to confirm that it represents your intentions.

    The execution plan is represented in the log for the plan job you ran previously.

    To review an execution plan (the log for the plan job) (Console)
    To review an execution plan (the log for the plan job) (CLI)
  4. Provision your resources by running an apply job against the execution plan.

    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.

    To run an apply job (Console)
    To run an apply job (CLI)
  5. Review the log entries and state file for the apply job you just ran.
    • See the entries in the job log for more details about the job.

      To view the job log (Console)
      To view the job log (CLI)
    • The job state file represents the job's output in JSON format.

      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 when you run jobs.

      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.

      To view the state of the job (Console)
      To view the state of the job (CLI)

      Note

      You can also import state files for resources already managed by Terraform.

  6. When you need to release the resources that you provisioned, run a destroy job on the stack.

    A destroy job tears down the stack that you created and then cleans up associated resources without deleting them. For example, the destroy job terminates Compute instances associated with the stack.

    To run a destroy job (Console)
    To run a destroy job (CLI)