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 your own Terraform configuration file with 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.
Note

You can use a solution instead of creating your own Terraform configuration file. A solution is an Oracle-provided, pre-built Terraform configuration that deploys cloud resources used in common scenarios. See Sample Solutions.

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:

Task 1: Create the Terraform Configuration

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. 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) within a .zip file to direct Resource Manager to execute the following sequence of operations.

Create an Oracle Cloud Infrastructure Provider

The following code sample creates a basic Oracle Cloud Infrastructure Terraform provider. You can provide values as variables that are defined either in a variables file or in the provider definition (.tf) file. For more information, see Provider Configuration.

provider "oci" {
  region = "${var.region}"
}
Define Variables

Define the variables you want to use when provisioning your resources. A best practice is to create a "variables" file in the configuration package that you upload. Following is an example from a configuration file that we've named variables.tf. For more information about using variables, see Input Variables. See also Configuring Input Variables.


variable "compartment_ocid" {
	default = "ocid1.compartment.oc1..uniqueid"
}

variable "region" {
	default = "us-phoenix-1"
}

variable "InstanceImageOCID" {
  type = "map"
  
  default = {
    // See https://docs.cloud.oracle.com/images/
    // Oracle-provided image "Oracle-Linux-7.5-2018.10.16-0"
    "eu-frankfurt-1" = "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaaitzn6tdyjer7jl34h2ujz74jwy5nkbukbh55ekp6oyzwrtfa4zma"
    "uk-london-1" = "ocid1.image.oc1.uk-london-1.aaaaaaaa32voyikkkzfxyo4xbdmadc2dmvorfxxgdhpnk6dw64fa3l4jh7wa"
    "us-ashburn-1" = "ocid1.image.oc1.iad.aaaaaaaageeenzyuxgia726xur4ztaoxbxyjlxogdhreu3ngfj2gji3bayda"
    "us-phoenix-1" = "ocid1.image.oc1.phx.aaaaaaaaoqj42sokaoh42l76wsyhn3k2beuntrh5maj3gmgmzeyr55zzrwwa"
  }
}


variable "ssh_public_key" {
	default = "ssh-rsa <public_key_value>"
}

# Defines the number of instances to deploy
variable "NumInstances" {
    default = "1"
}

variable "InstanceShape" {
    default = "VM.Standard2.1"
}

# Specifies the Availability Domain
variable "localAD" {
    default = "<AD_name>"
}

For more information about variables declared in the preceding examples, see the following:

Create a Virtual Cloud Network (VCN)

The following code sample creates an Oracle Cloud Infrastructure virtual cloud network (VCN) named "ExampleVCN."

resource "oci_core_virtual_network" "ExampleVCN" {
  cidr_block = "10.1.0.0/16"
  compartment_id = "${var.compartment_ocid}"
  display_name = "TFExampleVCN"
  dns_label = "tfexamplevcn"
}
Create a Subnet in Your VCN

The following code sample creates a subnet named "ExampleSubnet" in the VCN defined in the previous code sample.

resource "oci_core_subnet" "ExampleSubnet" {
  availability_domain = "${var.localAD}"
  cidr_block = "10.1.20.0/24"
  display_name = "TFExampleSubnet"
  dns_label = "tfexamplesubnet"
  security_list_ids = ["${oci_core_virtual_network.ExampleVCN.default_security_list_id}"]
  compartment_id = "${var.compartment_ocid}"
  vcn_id = "${oci_core_virtual_network.ExampleVCN.id}"
  route_table_id = "${oci_core_route_table.ExampleRT.id}"
  dhcp_options_id = "${oci_core_virtual_network.ExampleVCN.default_dhcp_options_id}"
}
Create an Internet Gateway

The following code sample creates an internet gateway named "ExampleIG" in the VCN that we created.

resource "oci_core_internet_gateway" "ExampleIG" {
  compartment_id = "${var.compartment_ocid}"
  display_name = "TFExampleIG"
  vcn_id = "${oci_core_virtual_network.ExampleVCN.id}"
}
Create a Core Route Table

The following code sample creates a Oracle Cloud Infrastructure core route table in the VCN and then applies two route rules.

resource "oci_core_route_table" "ExampleRT" {
  compartment_id = "${var.compartment_ocid}"
  vcn_id = "${oci_core_virtual_network.ExampleVCN.id}"
  display_name = "TFExampleRouteTable"
  route_rules {
    cidr_block = "0.0.0.0/0"
    network_entity_id = "${oci_core_internet_gateway.ExampleIG.id}"
  }
}
Create a Compute Instance

The following extended code example creates an Oracle Cloud Infrastructure Compute instance. The code also references the image on which the Compute instance is created, sets boot volume size, adds essential metadata, and applies both free-form and defined tags.

resource "oci_core_instance" "TFInstance" {
  count = "${var.NumInstances}"
  availability_domain = "${var.localAD}"
  compartment_id = "${var.compartment_ocid}"
  display_name = "TFInstance${count.index}"
  shape = "${var.InstanceShape}"
 
  create_vnic_details {
    subnet_id = "${oci_core_subnet.ExampleSubnet.id}"
    display_name = "primaryvnic"
    assign_public_ip = true
    hostname_label = "tfexampleinstance${count.index}"
  }
 
  source_details {
    source_type = "image"
    source_id = "${var.InstanceImageOCID[var.region]}"
 
    # Apply this to set the size of the boot volume that's created for this instance.
    # Otherwise, the default boot volume size of the image is used.
    # This should only be specified when source_type is set to "image".
    #boot_volume_size_in_gbs = "60"
  }


    # Apply the following flag only if you wish to preserve the attached boot volume upon destroying this instance
  # Setting this and destroying the instance will result in a boot volume that should be managed outside of this config.
  # When changing this value, make sure to run 'terraform apply' so that it takes effect before the resource is destroyed.
  #preserve_boot_volume = true
 
  metadata = {
    ssh_authorized_keys = "${var.ssh_public_key}"
  
  }
  timeouts {
    create = "60m"
  }
}
Finalize the Configuration

Ensure that all of the configuration files are in a single directory. You can store your Terraform configuration file locally or in a source code control system. For more information on storing your file in a source code control system, see Managing Configuration Source Providers (Console). Wherever your file is stored, you can select it when creating a stack using the CLI or Console.

Important

Make sure your Terraform configuration file is valid. See Writing Terraform Configurations and Terraform Configurations for Resource Manager.

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.

    You can create a stack from a remote, versioned file in a source code control system or a locally accessed file that you upload.

    To create a stack (Console)
    1. Open the navigation menu. Under Solutions and Platform, go to Resource Manager and click Stacks.
    2. Choose a compartment you have permission to work in (on the left side of the page). The page updates to display only the resources in that compartment. If you're not sure which compartment to use, contact an administrator.

    3. Click Create Stack.
    4. In the Create Stack dialog, select the option related to the location of your Terraform configuration.
      • My Configuration: Locally accessed file you want to upload.

        You can either drag and drop it onto the dialog's control or click Browse and navigate to the file location.

        The dialog box is populated with information contained in the configuration file.

      • Source Code Control System: Remote, versioned file you want to reference.

        See Prerequisites for connecting to GitLab.

    5. For a remote, versioned file (Source Code Control System), do the following:

      1. Select a Configuration Source Provider.

        If you need to create one, see To create a configuration source provider.

      2. Select a Repository.

        Example: https://gitlab.com/example

      3. Select a Branch.

        The list returned is limited to 100 branches.

      4. (Optional) Specify a Working Directory for running Terraform.

        Example (one level): Directory

        Example (two levels): Directory/Subdirectory

        If not specified, the root directory is used.

    6. Enter a Name for the new stack (or accept the default name provided).
    7. Optionally enter a Description.
    8. 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.

    9. Select a Terraform Version.

      Note

      Terraform version 0.12.x is not backward-compatible.
    10. Optionally, you can apply tags. If you have permissions to create a resource, you also have permissions to apply free-form tags to that resource. To apply a defined tag, you must have permissions to use the tag namespace. For more information about tagging, see Resource Tags. If you are not sure if you should apply tags, skip this option (you can apply tags later) or ask your administrator.
    11. Click Next.

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

    12. Review the variables and make changes as necessary.

      Important

      Do not add your private key or other confidential information to configuration variables.
    13. Click Next.
    14. In the Review panel, verify your stack configuration.
    15. Click Create to create your stack.
    To create a stack (CLI)

    Use the command related to your file location.

    To create a stack from a remote, versioned file

    Open a command prompt and run resource-manager stack create-from-git-provider to create a stack from a file tracked with a configuration source provider: 

    oci resource-manager stack create-from-git-provider --compartment-id <compartment_OCID> --config-source-configuration-source-provider-id <configuration_source_provider_OCID> --config-source-repository-url <repository_url> --config-source-branch-name <branch_name> --display-name "<friendly_name>" --description "<description>" --terraform-version "<version>" --variables <var_file_path> --working-directory "<directory>"
    Note

    You can return later to update stack settings or add variables after you have created the stack.

    For a complete list of flags and options available for CLI commands, see CLI Help.

    For example: 

    oci resource-manager stack create-from-git-provider --compartment-id ocid1.tenancy.oc1..uniqueid --config-source-configuration-source-provider-id ocid.ormconfigsourceprovider.oc1..uniqueid --config-source-repository-url https://github.com/user/repo.git --config-source-branch-name mybranch --display-name "My Stack from Git" --description "My Test" --variables file://variables.json --working-directory ""
    To create a stack from an uploaded file

    This section describes how to create a stack from an uploaded configuration file (.zip).

    Note

    You can also create stacks from configuration files stored in source code control systems, such as Git, and from sample solutions.

    On Windows, be sure the .zip file and variables.json files are in the same directory from which you're running the CLI. The CLI currently has a limitation on Windows that prevents correct handling of the files if either one is in a subdirectory.

    Open a command prompt and run oci resource-manager stack create to create a stack: 

    oci resource-manager stack create --compartment-id <compartment_OCID> --config-source <config_file_name> --variables <var_file_path> --display-name "<friendly_name>" --description "<description>" --working-directory ""
    Note

    You can return later to update stack settings or add variables after you have created the stack.
    Options

    For a complete list of flags and options available for CLI commands, see CLI Help.

    • --compartment-id is the OCID of the compartment where you want to create the stack.
    • --config-source is the name of a .zip file that contains one or more Terraform configuration files.
    • --variables is the path to the file specifying input variables for your resources. Optional.

      The Oracle Cloud Infrastructure Terraform provider requires additional parameters when running Terraform locally (unless you are using instance principals). For more information on using variables in Terraform, see Input Variables. See also Input Variable Configuration.

    • --display-name is the friendly name for the new stack. Optional.
    • --description is the description for the new stack. Optional.
    • --working-directory is the root configuration file in the directory. Optional. If not specified, or if null as in this example, then the service assumes that the top-level file in the directory is the root configuration file.

    For example: 

    oci resource-manager stack create --compartment-id ocid1.tenancy.oc1..uniqueid --config-source vcn.zip --variables file://variables.json --display-name "My Example Stack" --description "My Tutorial to Create a VCN" --working-directory ""
    Example response
    {
                            "data": {
                            "config-source": {
                            "working-directory": null,
                            "config-source-type": "ZIP_UPLOAD"
                            },
                            "defined-tags": {},
                            "description": "My Tutorial to Create a VCN",
                            "display-name": "My Example Stack",
                            "freeform-tags": {},
                            "id": "ocid1.ormstack.oc1..uniqueid",
                            "lifecycle-state": "ACTIVE",
                            "time-created": "2019-04-03T18:26:56.299000+00:00",
                            "variables": {
                            "compartment_ocid": "ocid1.compartment.oc1..uniqueid", 
                            "region": "us-phoenix-1"
                            }
                            }
                            }
  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)
    1. Open the navigation menu. Under Solutions and Platform, go to Resource Manager and click Stacks.
    2. Choose a compartment you have permission to work in (on the left side of the page). The page updates to display only the resources in that compartment. If you're not sure which compartment to use, contact an administrator.

    3. Click the name of the stack that you want to use.

      The Stack Details page is displayed.

    4. Go to Terraform Actions and select Plan.

    5. In the Plan dialog, review the plan job Name and update it if needed.
    6. Click Plan.

      The new plan job is listed under Jobs, with an initial state of "Accepted." Soon the status changes to "In Progress." When the job is complete, you can review the execution plan or download the job information.

    To run a plan job (CLI)

    Open a command prompt and run oci resource-manager job create-plan-job to run a plan job on the specified stack (--display-name is optional): 

    oci resource-manager job create-plan-job –-stack-id <stack_OCID> --display-name "<friendly_name>"

    Depending on the complexity of the configuration, the plan job can take several minutes to complete. When the job is complete, make sure you review the generated execution plan before running an apply job.

    To check the current state of the plan job

    Open a command prompt and run oci resource-manager job get to retrieve information about the job: 

    oci resource-manager job get –-job-id <plan_job_OCID>
    Lifecycle states
    Possible values for lifecycle-state:
    • ACCEPTED: The job is queued for execution.
    • IN_PROGRESS: The job is running.
    • FAILED: The job has failed and stopped running.
    • SUCCEEDED: The job has completed successfully.
    • CANCELING: The job has been notified to cancel, but has not yet stopped running.
    • CANCELED: The job was canceled and has stopped running.
    Example response

    This example shows ACCEPTED for lifecycle-state.

    {
                                        "data": {
                                        "compartment-id": " ocid1.compartment.oc1..uniqueid",
                                        "defined-tags": null,
                                        "display-name": "Example Plan Job",
                                        "freeform-tags": {},
                                        "id": "ocid1.ormjob.oc1..uniqueid",
                                        "lifecycle-state": "ACCEPTED",
                                        "operation": "PLAN",
                                        "jobOperationDetails": {
                                        "operation": "PLAN"
                                        },
                                        "stack-id": " ocid1.ormstack.oc1..uniqueid",
                                        "time-created": "2019-03-09T20:52:13.922000+00:00",
                                        "time-finished": null,
                                        "variables": {
                                        "compartment_ocid": "ocid1.compartment.oc1..uniqueid",
                                        "region": "us-phoenix-1"
                                        }
                                        }
                                        }
  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)
    1. Open the navigation menu. Under Solutions and Platform, go to Resource Manager and click Jobs.

      You can also access jobs from a stack detail page. Click Stacks and then click the name of the stack you want.

    2. Choose a compartment you have permission to work in (on the left side of the page). The page updates to display only the resources in that compartment. If you're not sure which compartment to use, contact an administrator.

    3. Click the name of the plan job that you ran.

    4. On the Job Details page, under Resources, click Logs.

      For plan jobs, the log file is the execution plan. View the log file for the plan job and note the "message" fields in the sequence of log entries of the log file. These values represent the sequence of operations specified in your configuration.

      You can also download the job information.

    If changes are needed, update your stack to use a revised configuration and then rerun the plan job to obtain an updated execution plan.

    To update the configuration for a stack
    Important

    Ensure that your Terraform configuration file is valid. See Writing Terraform Configurations and Terraform Configurations for Resource Manager.
    Note

    These instructions don't apply to configurations stored in source code control systems. You can store your Terraform configuration file locally or remotely, using a source code control system. With remote storage, any job running on the associated stack automatically uses the latest version of your configuration. For more information about remotely storing your file, see Managing Configuration Source Providers (Console).
    1. Ensure you have your revised Terraform configuration (.zip) file ready for upload.

      To edit a configuration file that was generated from a sample solution, first download the configuration. Then use the edited configuration file for the update.

    2. Open the navigation menu. Under Solutions and Platform, go to Resource Manager and click Stacks.
    3. Choose a compartment you have permission to work in (on the left side of the page). The page updates to display only the resources in that compartment. If you're not sure which compartment to use, contact an administrator.

    4. Click the name of the stack that you want to update.

      The Stack Details page is displayed.

    5. In the Stack Information tab, next to Terraform Configuration File (.zip), click Upload New.
    6. In the Edit Stack dialog, add your revised Terraform configuration (.zip) file.

      You can either drag and drop it onto the dialog's control or click Browse and navigate to the file location.

      The dialog box is populated with information contained in the configuration file.

    7. Click Next as needed and then click Save Changes.

      Now you can generate a new execution plan using your revised configuration.

    To review an execution plan (the log for the plan job) (CLI)

    View the log file and note the "message" fields in the sequence of log entries of the log file. You can view the log file for the specified job as either a paged list of entries or in its raw form.

    To view the log as a paged list of entries, open a command prompt and run oci resource-manager job get-job-logs:

    oci resource-manager job get-job-logs --job-id <job_OCID>

    To view the log in raw form, open a command prompt and run oci resource-manager job get-job-logs-content:

    oci resource-manager job get-job-logs-content --job-id <job_OCID>

    If changes are needed, update your stack to use a revised configuration and then rerun the plan job to obtain an updated execution plan.

  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)
    1. Open the navigation menu. Under Solutions and Platform, go to Resource Manager and click Stacks.
    2. Choose a compartment you have permission to work in (on the left side of the page). The page updates to display only the resources in that compartment. If you're not sure which compartment to use, contact an administrator.

    3. Click the name of the stack that you want to use.

      The Stack Details page is displayed.

    4. Go to Terraform Actions and select Apply.

    5. In the Apply dialog, review the apply job Name and other settings and update it if needed.
    6. Click Apply.

      The new apply job is listed under Jobs. Monitor its status: "Succeeded" indicates that the job has completed. While the job runs, or after it completes, you can download its log file.

    7. To view the Terraform state file (shows the state of your resources after running the job), click the name of the apply job and then click View State under Resources.

    To run an apply job (CLI)

    To check the current state of the apply job

    Open a command prompt and run oci resource-manager job create-apply-job with the relevant value for --execution-plan-strategy (examples use --display-name, which is optional): 

    • To specify a plan job ("apply" an execution plan), use FROM_PLAN_JOB_ID:

      oci resource-manager job create-apply-job --stack-id <stack_OCID> --execution-plan-strategy FROM_PLAN_JOB_ID --execution-plan-job-id <plan_job_OCID> --display-name "Example Apply Job"

      Use this option to "apply" your confirmed execution plan to the stack, execute the instructions, and provision the stack with the specified resources.

    • To automatically approve the apply job (no plan job specified), use AUTO_APPROVED:

      oci resource-manager job create-apply-job --stack-id <stack_OCID> --execution-plan-strategy AUTO_APPROVED --display-name "Example Apply Job"

    Depending on the complexity of your execution plan, the operation can take some time. Periodically check the lifecycle state of your apply job to see when it switches from IN_PROGRESS to SUCCEEDED.

    To check the current state of the apply job

    Open a command prompt and run oci resource-manager job get to retrieve information about the job: 

    oci resource-manager job get –-job-id <apply_job_OCID>
    Lifecycle states
    Possible values for lifecycle-state:
    • ACCEPTED: The job is queued for execution.
    • IN_PROGRESS: The job is running.
    • FAILED: The job has failed and stopped running.
    • SUCCEEDED: The job has completed successfully.
    • CANCELING: The job has been notified to cancel, but has not yet stopped running.
    • CANCELED: The job was canceled and has stopped running.

    To confirm existence of newly provisioned resources, inspect resources in the compartment.

  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)
      1. Open the navigation menu. Under Solutions and Platform, go to Resource Manager and click Jobs.

        You can also access jobs from a stack detail page. Click Stacks and then click the name of the stack you want.

      2. Choose a compartment you have permission to work in (on the left side of the page). The page updates to display only the resources in that compartment. If you're not sure which compartment to use, contact an administrator.

      3. Click the name of the plan job that you ran.

      4. On the Job Details page, under Resources, click Logs.

        For plan jobs, the log file is the execution plan. View the log file for the plan job and note the "message" fields in the sequence of log entries of the log file. These values represent the sequence of operations specified in your configuration.

        You can also download the job information.

      To view the job log (CLI)

      View the log file and note the "message" fields in the sequence of log entries of the log file. You can view the log file for the specified job as either a paged list of entries or in its raw form.

      To view the log as a paged list of entries, open a command prompt and run oci resource-manager job get-job-logs:

      oci resource-manager job get-job-logs --job-id <job_OCID>

      To view the log in raw form, open a command prompt and run oci resource-manager job get-job-logs-content:

      oci resource-manager job get-job-logs-content --job-id <job_OCID>
    • 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)
      1. Open the navigation menu. Under Solutions and Platform, go to Resource Manager and click Jobs.

        You can also access jobs from a stack detail page. Click Stacks and then click the name of the stack you want.

      2. Choose a compartment you have permission to work in (on the left side of the page). The page updates to display only the resources in that compartment. If you're not sure which compartment to use, contact an administrator.

      3. Click the name of the job you want.
      4. On the Job Details page, click View State under Resources.
      To view the state of the job (CLI)

      Open a command prompt and run oci resource-manager job get-job-tf-state to download the Terraform state of the specified job to the specified file: 

      oci resource-manager job get-job-tf-state --job-id <job_OCID> --file <output_file_name>
      Example response for an apply job
      {
                      "data": {
                      "lineage": "57ef4f0c-c8cd-8a32-d45f-d2c40be7b915",
                      "modules": [
                      {
                      "depends_on": [],
                      "outputs": {},
                      "path": [
                      "root"
                      ],
                      "resources": {
                      "oci_core_virtual_network.vcn1": {
                      "depends_on": [],
                      "deposed": [],
                      "primary": {
                      "attributes": {
                      "cidr_block": "10.0.0.0/16",
                      "compartment_id": "ocid1.tenancy.oc1..uniqueid",
                      "default_dhcp_options_id": "ocid1.dhcpoptions.oc1.phx.uniqueid",
                      "default_route_table_id": "ocid1.routetable.oc1.phx.uniqueid",
                      "default_security_list_id": "ocid1.securitylist.oc1.phx.uniqueid",
                      "display_name": "My VCN display name",
                      "dns_label": "myvcntest",
                      "id": "ocid1.vcn.oc1.phx.uniqueid",
                      "state": "AVAILABLE",
                      "time_created": "2018-05-24 01:13:05.855 +0000 UTC",
                      "vcn_domain_name": "myvcntest.oraclevcn.com"
                      },
                      "id": "ocid1.vcn.oc1.phx.uniqueid",
                      "meta": {
                      "e2bfb730-ecaa-11e6-8f88-34363bc7c4c0": {
                      "create": 300000000000,
                      "delete": 300000000000,
                      "update": 300000000000
                      }
                      },
                      "tainted": false
                      },
                      "provider": "provider.oci",
                      "type": "oci_core_virtual_network"
                      }
                      }
                      }
                      ],
                      "serial": 4,
                      "terraform_version": "0.11.7",
                      "version": 3
                      }
                      }
      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)
    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.
    1. Open the navigation menu. Under Solutions and Platform, go to Resource Manager and click Stacks.
    2. Choose a compartment you have permission to work in (on the left side of the page). The page updates to display only the resources in that compartment. If you're not sure which compartment to use, contact an administrator.

    3. Click the name of the stack that you want to use.

      The Stack Details page is displayed.

    4. Go to Terraform Actions and select Destroy.
    5. Click Destroy again to confirm your action.

      You can monitor the status and review the results of a destroy job by viewing the state or the logs.

    6. To view the Terraform state file (shows the state of your resources after running the job), click the name of the job to display the Job Details page, then click View State under Resources.
    7. To view the logs for the job, click the name of the job to display the Job Details page, then click Logs under Resources.
    To run a destroy job (CLI)
    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.

    Open a command prompt and run oci resource-manager job create-destroy-job to tear down and clean up the resources provisioned by the specified stack: 

    oci resource-manager job create-destroy-job --stack-id <stack_OCID> --execution-plan-strategy=AUTO_APPROVED

    To confirm deletion of the resources, inspect resources in the compartment.