Provision Resources During Deployment
Create a single pipeline to provision or update resources during deployment. This pattern combines IaCM and CD stages in a single pipeline, allowing you to provision infrastructure and then deploy applications that use those resources.
Before you begin
-
Harness account with IaCM and CD enabled: You need both Infrastructure as Code Management and Continuous Delivery modules. For how to access or create a Harness account, see Getting started with Harness Platform.
Contact Harness support:If IaCM or CD does not appear, see Get started with IaCM or contact your account administrator or Harness Support.
-
Pipeline permissions: You need View, Create/Edit, and Execute for Pipelines. To get these, an administrator must assign you a role that includes them. See RBAC in Harness and Manage roles.
-
IaCM workspace configured: You need an existing workspace with Terraform or OpenTofu configuration. Go to Create a workspace to set one up.
Pipeline stages overview
A combined IaCM and CD pipeline includes two stages:
- IaCM Stage: This stage provisions or updates resources, setting the groundwork for your deployment.
- CD Stage: This stage uses the resources provisioned in the IaCM stage to deploy your application.
Go to CD steps, stages, and strategies for information about CD stages.
Pass variables between stages
You can pass variables from an IaCM pipeline to a CD stage. For example, pass the Kubernetes namespace as a value.
After executing a pipeline, select the Apply step to view all OpenTofu or Terraform outputs as output expressions. Copy these for use in subsequent steps or stages, even across different pipelines.

Example: Pass a variable
To use the "bucket_name" as an input, copy the current value or the path to the variables. This ensures the value is fetched at runtime:
<+pipeline.stages.iacstage.spec.execution.steps.apply.output.outputVariables.bucket_name>

Troubleshooting
IaCM stage output variables not available in CD stage
Ensure the Apply step completed successfully in the IaCM stage. Use the correct expression syntax: <+pipeline.stages.STAGE_ID.spec.execution.steps.apply.output.outputVariables.VARIABLE_NAME>
CD stage fails to access infrastructure provisioned by IaCM stage
Verify that the IaCM Apply step completed and the resources were created. Check the IaCM stage logs and confirm the outputs are exported. Ensure the CD stage has the correct connector and credentials.
Output variable expression returns empty value in CD stage
Check that the Terraform or OpenTofu configuration defines the output block correctly. Outputs must be explicitly declared in the IaC code to appear as variables.
Next steps
You have successfully combined IaCM and CD stages in a single pipeline. You can now provision infrastructure and deploy applications in one workflow.
- Go to Approval step to add manual approval gates before applying infrastructure changes.
- Go to OPA policies to enforce governance rules during pipeline execution.
- Go to Default pipelines to configure reusable pipeline templates.