Getting Started

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.

This page helps you get started with Resource Manager. Use this end-to-end walkthrough of tasks to create and deploy an Oracle Cloud Infrastructure compute instance using either a prebuilt Terraform configuration or your own Terraform configuration. For a brief introduction to Resource Manager, see Overview of Resource Manager.

Highlights

In addition to providing a prebuilt Terraform configuration for creating a Compute instance, this walkthrough provides samples that demonstrate how to write a Terraform configuration. Whichever configuration you use (prebuilt or your own), Resource Manager uses Terraform to provision the defined resources . The resources are organized into stacks, which you create and provision using jobs.

The walkthrough covers the following tasks:

  • Select or create a Terraform configuration.
  • 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.
  • Optionally provision the infrastructure in more environments, using the same Terraform configuration.

Before You Begin

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

  • An Oracle Cloud Infrastructure tenancy for each environment where you want to provision resources. For example, you might provision the resources defined in a Terraform configuration to development, staging, and production environments.
    Note

    It is a best practice to locate each environment in its own tenancy.
  • The OCID  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 Configuring the CLI

Task 1a: Select a prebuilt Terraform Configuration

You can select the compute instance template with its prebuilt Terraform configuration instead of writing your own configuration. These steps guide you through the stack creation process.

  1. Select the following link to launch the Create stack page with the compute instance template already selected.

    Launch stack with Compute Instance template

  2. In the Create stack page, enter a Name for the new stack (or accept the default name provided). Avoid entering confidential information.
  3. From the Create in compartment drop-down, select the compartment where you want to create the stack.

    A compartment from the list scope is set by default.

  4. Select Next.

    The Configure variables panel displays variables from the Terraform configuration.

  5. Review the variables and make changes as necessary.

    Important

    Do not add your private key or other confidential information to configuration variables.
  6. Select Next.
  7. In the Review panel, verify your stack configuration.

    For purposes of this walkthrough, leave Run apply blank. (Use this option to automatically provision the infrastructure when the stack is created.)

  8. Select Create to create your stack.

    The stack details page for the new stack appears.

    Congratulations! You have created a stack with the prebuilt Terraform configuration from the compute instance template. The next step is to provision the infrastructure.

Task 1b: Create Your Own Terraform Configuration

If you didn't select a prebuilt Terraform configuration, then follow these steps to write your own.

A Terraform configuration is a file that codifies your infrastructure. The configuration defines your Terraform provider, the resources you intend to provision, variables, and specific instructions for provisioning the resources.

This page guides you through selecting the compute Instance template with its prebuilt Terraform configuration or alternatively writing your own configuration using several .tf files within a .zip file.

For more information about writing configurations for use with Resource Manager, see Terraform Configurations for Resource Manager and Terraform Language Documentation.

Caution

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

Task 2: Provision the Infrastructure

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

  1. If you created your own Terraform configuration, follow these steps to create a stack in a tenancy compartment of your choosing. (If you selected a prebuilt configuration, skip this step.)

    For Terraform configuration sources supported with Resource Manager, see Where to Store Your Terraform Configurations.

    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.

    You can create a stack from a remote, versioned file in a source code control system (such as Git), an Object Storage bucket, or a locally accessed .zip file that you upload. Following are instructions for a local file.

  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.

    Note

    You can skip this step if you selected Run apply when you created the stack. In this case, the resources have already been provisioned.
  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.

    Note

    You can skip this step if you selected Run apply when you created the stack. In this case, the resources have already been provisioned.
  4. Provision your resources by running an apply job against the execution plan.

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

    Note

    You can skip this step if you selected Run apply when you created the stack. In this case, the resources have already been provisioned.
  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.

    • 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 State.

      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.

    Note

    We recommend running a destroy job before deleting a stack to release associated resources first. When you delete a stack, its associated state file is also deleted; therefore, you lose track of the state of its associated resources. Cleaning up resources associated with a deleted stack can be difficult without the state file, especially when those resources are spread across multiple compartments. To avoid difficult cleanup later, we recommend that you release associated resources first by running a destroy job.

    Data cannot be recovered from destroyed resources.

Task 3: Repeat in More Environments

This section describes how to build and deploy infrastructure in multiple environments.

In this scenario, you use the same Terraform configuration .zip file to provision a Compute instance in your development, staging, and production environments.

Note

This scenario assumes that the Terraform configuration includes a schema document, which allows you to change variable values when creating a stack in the Console.
  1. Access the tenancy for the new environment where you want to provision the infrastructure defined in your Terraform configuration.

    For example, access the tenancy for your staging or production environment.

  2. Open the Create stack page:
    1. Open the navigation menu  and select Developer Services. Under Resource Manager, select Stacks.
    2. Under List Scope, select a compartment that you have permission to work in. The page updates to display only the resources in that compartment. If you're not sure which compartment to use, contact an administrator.

    3. Select Create stack.
  3. Using the same Terraform configuration as for the first environment, complete the Stack information tab:

    1. On the Create stack page, select My configuration.

    2. Under Stack configuration, select .Zip file and add the Terraform configuration.

      You can either drag and drop your Terraform configuration .zip file onto the control or select Browse and navigate to the location of the .zip file.

    3. Enter a Name for the new stack (or accept the default name provided). Avoid entering confidential information.
    4. Optionally enter a Description.
    5. From the Create in compartment drop-down, select the compartment where you want to create the stack.

    6. Select Next.

      The Configure variables panel displays variables from the selected Terraform configuration file.

  4. Specify the variable values for this environment:

    1. In the Configure variables panel, review the variables and make changes as necessary.

      Default values are provided when specified in the schema document.

      Important

      Do not add your private key or other confidential information to configuration variables.
    2. Select Next.
  5. In the Review panel, verify your stack configuration.
  6. To automatically provision resources on creation of the stack, select Run apply.
  7. Select Create to create your stack.

    The stack details page for the new stack appears.

    If you selected Run apply, then Resource Manager runs the apply action on the new stack.

Congratulations, you have reused your Terraform configuration to create a stack in a new environment. If you selected Run apply, then you also provisioned resources in the new environment.

You can now generate and review an execution plan (and provision resources, if Run apply wasn't selected). To complete these items, repeat the steps from Task 2: Provision the Infrastructure in the new environment.