---
name: ContinuousDelivery-terraform
title: Setting up Terraform for Continuous Delivery
description: Terraform on IBM Cloud&reg; enables predictable and consistent creation of IBM Cloud services so that you can rapidly build complex, multitier cloud environments by following Infrastructure as Code (IaC) principles. Similar to using the IBM Cloud CLI or API and SDKs, you can automate the creation, update, and deletion of your IBM Cloud&reg; Continuous Delivery instances by using the HashiCorp Configuration Language (HCL).
last-updated: 2026-07-23
---

> ## Documentation Index
> The table of contents for this documentation set is at https://cloud.ibm.com/docs/ContinuousDelivery?format=markdown
> The index for all IBM Cloud docs is at: https://cloud.ibm.com/docs/llms.txt
> Use these files to discover more information as needed.

# Setting up Terraform for Continuous Delivery
{: #terraform-setup}

DevOps Insights will reach end of service and be discontinued on **August 31, 2026**. Continuous Delivery will be discontinued in the following regions on 12 February 2027: **au-syd**, **ca-mon**, **ca-tor**, **us-east**. Code Risk Analyzer will also be discontinued in all regions on that date. If a region has no active usage of these features, the features in that region may be discontinued earlier and stop accepting new instances. [Learn more](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-faq_region_feature_consolidation&format=markdown)
{: important}

Terraform on IBM Cloud&reg; enables predictable and consistent creation of IBM Cloud services so that you can rapidly build complex, multitier cloud environments by following Infrastructure as Code (IaC) principles. Similar to using the IBM Cloud CLI or API and SDKs, you can automate the creation, update, and deletion of your IBM Cloud&reg; Continuous Delivery instances by using the HashiCorp Configuration Language (HCL).
{: shortdesc}

Looking for a managed Terraform on IBM Cloud&reg; solution? Try out [IBM Cloud&reg; Schematics](https://cloud.ibm.com/docs/schematics?topic=schematics-getting-started&format=markdown). With Schematics, you can use the Terraform scripting language that you are familiar with without worrying about setting up and maintaining the Terraform command line and the IBM Cloud&reg; Provider plug-in. Schematics also provides pre-defined Terraform templates that you can easily install from the IBM Cloud&reg; catalog.
{: tip}

## Installing Terraform and configuring resources for Continuous Delivery
{: #install-terraform}

Before you begin, make sure that you have the [required access](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-cd-iam-security&format=markdown) to create and work with `continuous-delivery` resources, and the [required access](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-toolchains-iam-security&format=markdown) to create and work with `toolchain` resources.

1. Follow the [Terraform on IBM Cloud getting started tutorial](https://cloud.ibm.com/docs/ibm-cloud-provider-for-terraform?topic=ibm-cloud-provider-for-terraform-getting-started&format=markdown) to install the Terraform CLI and configure the IBM Cloud Provider plug-in for Terraform. The plug-in abstracts the IBM Cloud APIs that are used to create, update, or delete `continuous-delivery` service instances and `toolchain` resources. 

2. Create a Terraform configuration file that is named `main.tf`. In this file, add the configuration to create a Continuous Delivery service instance and to assign a user an access policy in Identity and Access Management (IAM) for that instance by using HCL. You also add the configuration to create a basic toolchain resource in the same resource group and region as the Continuous Delivery service instance, and to assign a user an access policy in IAM for that resource. The toolchain and the Continuous Delivery service instance that governs usage of the toolchain are in the same resource group and region. For more information about working with the Terraform configuration file, see the [Terraform documentation](https://developer.hashicorp.com/terraform/language){: external}. 

   The Continuous Delivery service instance in the following example is named `my_cd`. It is created with the professional pricing plan in the `default` resource group and in the `us-south` region. The user `user1@ibm.com` is assigned the Manager role in the IAM access policy for the service instance.

   The toolchain resource is named `my_toolchain`. It is created in the `default` resource group and in the region that is specified in the `provider "ibm"` block in your `provider.tf` file. For this example, the `region` in `provider.tf` is set to `us-south`. The user `user2@ibm.com` is assigned the Editor role in the IAM access policy for the toolchain resource.

   ```terraform
   data "ibm_resource_group" "default_rg" {
     name = "default"
   }

   resource "ibm_resource_instance" "cd_instance" {
     name              = "my_cd"
     service           = "continuous-delivery"
     plan              = "professional"
     location          = "us-south"
     resource_group_id = data.ibm_resource_group.default_rg.id
   }

   resource "ibm_iam_user_policy" "cd_policy" {
     ibm_id = "user1@ibm.com"
     roles  = ["Manager"]
     resources {
       service              = "continuous-delivery"
       resource_instance_id = element(split(":", ibm_resource_instance.cd_instance.id), 7)
     }
   }

   resource "ibm_cd_toolchain" "toolchain_instance" {
     name              = "my_toolchain"
     resource_group_id = data.ibm_resource_group.default_rg.id
   }

   resource "ibm_iam_user_policy" "toolchain_policy" {
     ibm_id = "user2@ibm.com"
     roles  = ["Editor"]
     resources {
       service              = "toolchain"
       resource_instance_id = ibm_cd_toolchain.toolchain_instance.id
     }
   }
   ```
   {: codeblock}

3. Initialize the Terraform CLI. 

   ```terraform
   terraform init
   ```
   {: pre}

4. Create a Terraform execution plan. The Terraform execution plan summarizes all of the actions that you must run to create the Continuous Delivery service instance, toolchain resource, and associated IAM access policies in your account.

   ```terraform
   terraform plan
   ```
   {: pre}

5. Create the Continuous Delivery service instance, toolchain resource, and associated IAM access policies in your account in IBM Cloud.

   ```terraform
   terraform apply
   ```
   {: pre}
   
6. From the [IBM Cloud resource list](https://cloud.ibm.com/resources){: external}, expand the Developer tools section, then select the Continuous Delivery service instance that you created and note the instance ID.

7. Verify that the access policy is successfully assigned. For more information about assigning access policies, see [Reviewing assigned access in the console](https://cloud.ibm.com/docs/iam?topic=iam-assign-access-resources&interface=ui&format=markdown#review-your-access-console).

8. From the [IBM Cloud resource list](https://cloud.ibm.com/resources){: external}, expand the Developer tools section, then select the toolchain resource that you created and note the instance ID.

9. Verify that the access policy is successfully assigned.

## Enabling Platform Logs for a Continuous Delivery service instance with Terraform
{: #enable_logs_cd_service_terraform}
{: terraform}

The Continuous Delivery service supports the ability to send Tekton `PipelineRun` logs as platform logs. This allows receiving all Tekton `PipelineRun` logs for the current region and resource group into your account, and you can configure your account to forward these received logs to a target such as IBM Cloud Logs.

1. In your Terraform configuration file adjust the configuration to include the `platform_logging_pipelineruns_enabled` parameter with a value of `true`.

   ```terraform
   data "ibm_resource_group" "group" {
     name = "default"
   }

   resource "ibm_resource_instance" "cd_instance" {
     name              = "my_cd"
     service           = "continuous-delivery"
     plan              = "professional"
     location          = "us-south"
     resource_group_id = data.ibm_resource_group.default_rg.id
     
     parameters = {
       platform_logging_pipelineruns_enabled = "true"
     }
   }
   ```
   {: codeblock}

## What's next?
{: #terraform-setup-next}

Now that you successfully created your first Continuous Delivery service instance and toolchain resource with Terraform on IBM Cloud, you can choose between the following tasks:

- [Deleting a Continuous Delivery service instance](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-delete_cd_service&format=markdown)
- [Using toolchains](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-toolchains-using&format=markdown)
- [Configuring tool integrations](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-integrations&format=markdown)
- [Working with Tekton pipelines](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-tekton-pipelines&format=markdown)
- [Working with Delivery Pipeline Private Workers](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-private-workers&format=markdown)
- [Creating toolchains with Git](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-toolchains_git&format=markdown)
- [Adding DevOps Insights to your toolchain](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-add-devops-insights&format=markdown)
- [Managing personal data for Continuous Delivery](https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-cd_personal_data&format=markdown)

For more information about IBM Cloud Provider resources and data sources, see the [Terraform Registry documentation](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs){: external}.