> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/cortex-xdr/configure-cortex-xdr/cortex-xdr-data-sources/cloud-service-provider-csp-onboarding/ibm-cloud-cloud-onboarding/deploy-the-terraform-authentication-template-in-ibm-cloud.md).

# Deploy the Terraform authentication template in IBM Cloud

Run the Cortex XDR Terraform authentication template in your IBM Cloud account, and then manually connect the pending cloud instance with the Terraform outputs.

After you download the Terraform authentication template from the IBM Cloud onboarding wizard, run it in your IBM Cloud account. Then manually connect the pending cloud instance in Cortex XDR with the values that Terraform outputs. Both parts are required to complete onboarding.

Before you begin, ensure you meet the [prerequisites for onboarding IBM Cloud](https://cortex-docs.paloaltonetworks.com/cortex-xdr/configure-cortex-xdr/cortex-xdr-data-sources/cloud-service-provider-csp-onboarding/ibm-cloud-cloud-onboarding/prerequisites-for-onboarding-ibm-cloud.md).

## Run the Terraform authentication template

Run the template from a machine that has Terraform installed. The template creates the read-only service ID, its custom roles and access policies, and an API key for the service ID.

1. Create a directory to store and run the Terraform files. If you onboard more than one IBM Cloud account, use a separate directory for each one.

   ```bash
   mkdir -p ~/terraform/ibm-cloud-connector-1
   ```
2. Navigate to the directory you created and extract the Terraform files from the archive you downloaded. Ensure all the Terraform files are present, including `template_params.tfvars`.

   <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p><strong>Important:</strong> Don't delete or move the Terraform files or the Terraform state file from this directory. You need them to rotate the API key, to apply future <a href="https://cortex-docs.paloaltonetworks.com/cortex-xdr/configure-cortex-xdr/cortex-xdr-data-sources/cloud-service-provider-csp-onboarding/ibm-cloud-cloud-onboarding/edit-an-ibm-cloud-cloud-instance.md">edits to the cloud instance</a>, and to offboard the account.</p></div>

   ```bash
   cd ~/terraform/ibm-cloud-connector-1
   tar -xzvf <your_template>.tar.gz
   ```
3. Set your IBM Cloud administrator API key as an environment variable. The IBM Cloud Terraform provider reads the key from this variable.

   ```bash
   export IC_API_KEY="<your IBM Cloud administrator API key>"
   ```
4. Initialize Terraform:

   ```bash
   terraform init
   ```
5. Apply the Terraform configuration with the downloaded parameter file:

   ```bash
   terraform apply --var-file=template_params.tfvars
   ```
6. When prompted, review the actions that Terraform performs, and then enter `yes` to approve them.

Terraform creates the resources in your IBM Cloud account. For the full list, see [IBM Cloud resource inventory](https://cortex-docs.paloaltonetworks.com/cortex-xdr/configure-cortex-xdr/cortex-xdr-data-sources/cloud-service-provider-csp-onboarding/ibm-cloud-cloud-onboarding/ibm-cloud-resource-inventory.md).

{% hint style="warning" %}
**Important:** Terraform writes the service ID API key to the Terraform state file (`terraform.tfstate`). Store the state file securely and restrict access to it.
{% endhint %}

## Retrieve the Terraform outputs

The template outputs the values you need to connect the cloud instance in Cortex XDR. Retrieve them in the same directory where you ran Terraform.

```bash
terraform output account_id
terraform output service_id
terraform output template_id
terraform output api_key
```

Check that the `account_id` output is the ID of the IBM Cloud account you want to onboard. You can find the account ID in the IBM Cloud console under **Manage → Account → Account settings**. If the account ID is different, you ran the template with an administrator API key from another account. Don't connect the cloud instance. Run `terraform destroy --var-file=template_params.tfvars` to remove the resources from that account, and then run the template again with an administrator API key from the correct account.

The `api_key` output is the API key for the service ID.

{% hint style="warning" %}
**Important:** Terraform shows the `api_key` value in clear text in the output of `terraform apply`, `terraform plan`, and `terraform output`. Copy the key securely. Don't share, log, or paste Terraform output, for example in support cases or chat, without removing the key.
{% endhint %}

## Manually connect the cloud instance

Enter the Terraform outputs in Cortex XDR to connect the pending cloud instance. Until you complete this step, the cloud instance stays in Pending status and Cortex XDR doesn't scan the account.

1. In Cortex XDR, select **Settings → Data Sources & Integrations**, and then open the **IBM Cloud** cloud instances.
2. On the **Cloud Instances** page, find the pending instance:
   * Remove the default filter that excludes pending instances.
   * To find the exact instance, filter the **Instance ID** column by the value of the `template_id` output. The instance ID of the pending instance is the same as the template ID.
3. Optional: To confirm you have the right instance, right-click it, select **View Details**, and check the instance name and settings.
4. Right-click the pending instance and select **Manually connect an instance**.
5. Enter the values in the **Connect Instance** form, as described in the following table:

   | Connect Instance input field | Value                                                                                               |
   | ---------------------------- | --------------------------------------------------------------------------------------------------- |
   | Authentication Method        | Select the Terraform authentication method. It's the only method available for IBM Cloud.           |
   | IBM Cloud Account ID         | The value of the `account_id` output.                                                               |
   | Service ID                   | The value of the `service_id` output (the service ID's IAM ID, which starts with `iam-ServiceId-`). |
   | API Key                      | The value of the `api_key` output.                                                                  |
6. Click **Connect**.

Cortex XDR validates the values, encrypts and stores the API key, and connects the cloud instance. The cloud instance status changes to Connected and the first discovery scan starts.

To confirm that onboarding succeeded, see [IBM Cloud post-deployment verification](https://cortex-docs.paloaltonetworks.com/cortex-xdr/configure-cortex-xdr/cortex-xdr-data-sources/cloud-service-provider-csp-onboarding/ibm-cloud-cloud-onboarding/ibm-cloud-post-deployment-verification.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cortex-docs.paloaltonetworks.com/cortex-xdr/configure-cortex-xdr/cortex-xdr-data-sources/cloud-service-provider-csp-onboarding/ibm-cloud-cloud-onboarding/deploy-the-terraform-authentication-template-in-ibm-cloud.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
