Creating a Destroy Job

Create a destroy job in Resource Manager to release (tear down) resources associated with a stack and clean up the tenancy. Released resources are eventually deleted by the related OCI service. For example, a released compute instance is eventually deleted by the OCI Compute service.

The stack's job history and state remain after running a destroy job. You can monitor the status and review the results of a destroy job by inspecting the stack's log files.

The destroy job is available when resources exist that were created by 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. If the stack has no associated resources, then a destroy job isn't available. You can safely delete such a stack without concern about missing state files.

Data cannot be recovered from destroyed resources.

    1. On the Stacks list page, select the stack that you want to work with. If you need help finding the list page or the stack, see Listing Stacks.
    2. On the stack's details page, select Destroy.
    3. (Optional) In the Destroy panel, edit the default name for the job. Avoid entering confidential information.
    4. To retrieve the latest versions available from the configured source of Terraform providers, select Show advanced options and select Upgrade provider versions.
      The stack must be Terraform 0.14 or later, and if the stack is older, it must be upgraded to use Terraform Registry.This step is required if provider versions in the Terraform configuration changed since the last time a job was run on the stack. Dependency lock files are automatically managed for new and updated stacks. Providers are updated within the version constraints of the Terraform configuration.
    5. To generate detailed log content for debugging, select Show advanced options and select the log level that you want from Detailed log level.
      For more information, see Debugging Terraform.
    6. To adjust the maximum number of concurrent operations as Terraform walks the graph, select Show advanced options and edit the value for Maximum number of parallel operations. (Default: 10.) Use this option to speed up the job.
      Note

      A high value might cause throttling of resources. For example, consider a Terraform configuration that defines hundreds of compute instances. An Apply job attempts to create as many instances as possible at the same time. In this example, a value of 100 might cause throttling by the Compute service.
    7. To fetch the latest state before running the job, select Show advanced options and select Refresh resource states before checking for differences.

      Use this option to refresh the state first. For example, consider using this option with an Apply job that you intend to run on manually updated (existing) infrastructure.

      Note

      Refreshing the state can affect performance. If the configuration includes several resources, consider not using this option.
    8. (Optional) Select Show advanced options and assign tags to the job.
      • Tag namespace: To add a defined tag, select an existing namespace. To add a free-from tag, leave the value blank.
      • Tag key: To add a defined tag, select an existing tag key. To add a free-form tag, type the key name that you want.
      • Tag value: Type the tag value that you want.
      • Add tag: Click to add another tag.
    9. Select Destroy.

    The destroy job is created. The new job is listed under Jobs.

  • Use the oci resource-manager job create-destroy-job command and required parameters to run a destroy job.

    oci resource-manager job create-destroy-job [OPTIONS]

    For a complete list of parameters and values for CLI commands, see the Command Line Reference for Resource Manager.

  • Use the CreateJob operation to create a destroy job.

    For an example of the operation part of the request, see CreateDestroyJobOperationDetails.

What's Next

After running a destroy job, get the job's details to check its status. You can optionally view the Terraform state file, view the logs, and confirm deletion of the resources. You can also re-create destroyed resources.

Monitor the job status (lifecycle state) by getting the job's details. Succeeded (SUCCEEDED) indicates that the job has completed. Depending on the complexity of the job, the operation can take some time. While the job runs, or after it finishes, you can get the job logs content.

To view the Terraform state file (shows the state of your resources after running the job), select the name of the job to display the Job details page, then select View state under Resources. Optionally select Show changes in this version.

To view the logs for the job, select the job to open its details page, then select Logs under Resources.

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

To re-create a stack's resources after the resources are destroyed, run an apply job. The new resources differ from previously destroyed resources by their unique OCIDs and other metadata.