Creating an Apply Job

Create an apply job in Resource Manager.

When you create (run) an apply job for a stack, Terraform provisions the resources and executes the actions defined in your Terraform configuration, applying the execution plan to the associated stack to create (or modify) your Oracle Cloud Infrastructure resources. We recommend running a plan job (generating an execution plan) before running an apply job.

For a walk-through using CLI for cloud provisioning in a CI/CD pipeline, see IaC in the Cloud: Integrating Terraform and Resource Manager into your CI/CD Pipeline - Building With the OCI CLI.

For configurations stored in a source code control system, such as GitHub or GitLab, the job uses the most recent commit. The time required to complete an apply job depends on the number and type of cloud resources to be created.

Tip

Depending on the number and type of resources specified, a given apply job can take some time.

After running an apply job, get the job's details to check its status. You can optionally view the Terraform state file, view the logs, and confirm existence of provisioned resources.

Monitor the job status (lifecycle state) by getting the job: Succeeded (SUCCEEDED) indicates that the job has completed. Depending on the complexity the job, the operation can take some time. While the job runs, or after it completes, 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.

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

Using the Console

  1. Open the navigation menu and click Developer Services. Under Resource Manager, click Stacks.
  2. Choose a compartment that you have permission to work in (on the left side of the page).
  3. Click the name of the stack that you want.
    The Stack details page opens.
  4. Click Apply.
  5. In the Apply panel, fill in the fields.
    FieldDescription
    Name Name of apply job.
    Apply job plan resolution Optionally select the name of the latest generated plan job. Only the latest generated plan job is available. If no plan job has been generated for this stack, then only the default value is available (Automatically approve). For more information about Automatically approve, see Auto-Approve Option for Terraform Apply Command.
  6. To configure advanced options, click Show advanced options and fill in the fields.
    FieldDescription
    Upgrade provider versions

    Upgrade provider versions (stack must be Terraform 0.14 and later; older stacks must be upgraded to use Terraform Registry): Retrieves the latest versions available from the configured source of Terraform providers.

    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 your Terraform configuration.

    Detailed log level

    Detailed log level: Verbosity to use for Terraform detailed log content for this job. Default: None (no detailed log content is generated).

    For more information, see Debugging Terraform.

    Maximum number of parallel operations

    Maximum number of parallel operations: Concurrent operations as Terraform walks the graph. Default: 10.

    Use this option to speed up the job.

    Note

    A high value might cause resources to be throttled. 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.

    Refresh resource states before checking for differences

    Refresh resource states before checking for differences: Fetch the latest state of stack infrastructure before running the job. Default: Enabled.

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

    Note

    Refreshing the state can affect performance. Consider disabling if the configuration includes several resources.

    Tags Optionally apply tags to the job.
  7. Click Apply.

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

Using the CLI

Use the oci resource-manager job create-apply-job command and required parameters to run an apply job.

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

For a complete list of flags and variable options for CLI commands, see the Command Line Reference for Resource Manager.

Examples

Example 1: Reference a plan job.

oci resource-manager job create-apply-job --execution-plan-strategy <plan_job_ocid> --stack-id <stack_ocid>

Example 2: Automatically approve (do not reference a plan job).

oci resource-manager job create-apply-job --execution-plan-strategy AUTO_APPROVED --stack-id <stack_ocid>

Using the API

Use the CreateJob operation to create an apply job.