Creating an Import Job

Create an import job in Resource Manager to import state files for existing resources already managed by Terraform. An import job sets the provided Terraform state file as the current state of the stack.

For example, use an import job to migrate a local Terraform environment to Resource Manager.

    1. Open the navigation menu and click Developer Services. Under Resource Manager, click Stacks.
    2. On the Stacks page, select the compartment that contains the stack that you want.
    3. Click the name of the stack that you want.
    4. On the Stack details page, go to More actions and select Import state.
    5. (Optional) In the Import panel, edit the default name for the job. Avoid entering confidential information.
    6. For Select a Terraform state file to upload, add the Terraform state file that you want to import into the stack.
      You can drag the file onto the control or click Browse and navigate to the file location.
    7. To retrieve the latest versions available from the configured source of Terraform providers, click 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.
    8. (Optional) Click 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. Click Import.

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

  • Use the oci resource-manager job create-import-tf-state-job command and required parameters to run an import job.

    oci resource-manager job create-import-tf-state-job --stack-id <stack_OCID> --tf-state-file <job_details>

    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 an import job.

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

What's Next

After running an import job, get the job's details to check its status. You can optionally view the Terraform state file and view the logs.

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), click the name of the job to display the Job details page, then click View state under Resources. Optionally select Show changes in this version.

To view the logs for the job, click the name of the job to open the Job details page, then click Logs under Resources.