CDK Pipeline Steps
Reference for the bootstrap, synth, diff, deploy, destroy, drift, and approval steps available in Harness IaCM CDK pipelines.
CDK workspaces in Harness IaCM use dedicated pipeline steps that correspond to the AWS CDK deployment lifecycle. Add these steps from the IaCM step category when you create a pipeline.
A typical deployment pipeline runs Bootstrap, Synth, Diff, and Deploy in sequence. Destroy and Drift are optional steps that you can run independently.
Go to Set up the AWS CDK provisioner to create the workspace that these steps run against.
Pipeline steps
Bootstrap
Bootstrap provisions the CDK toolkit resources required to deploy applications into the target AWS account and Region. These resources include:
An Amazon S3 bucket for CloudFormation assets.
An Amazon ECR repository for container image assets.
Bootstrap is required only once for each AWS account and Region. After the toolkit resources exist, later pipeline runs detect them and continue without creating them again.
Bootstrap is idempotent and safe to include in every deployment pipeline. If your workspace targets a single account and Region, you can also run it once and remove it from later runs.
Go to AWS Connector Authentication to review the IAM permissions required for bootstrap. Go to Bootstrapping your AWS CDK environment in the AWS CDK Developer Guide to review what resources the toolkit creates.
Synth
Synth compiles your CDK application into one AWS CloudFormation template for each stack defined in the application. During this step, Harness installs your application's dependencies, runs cdk synth, and generates the CloudFormation templates and asset manifest in the cdk.out directory.
If the application contains compilation or validation errors, the pipeline fails before any AWS resources are created or updated. OPA policies for CDK evaluate the templates generated during this step. If a policy denies the synthesized template, the pipeline fails. Go to OPA Policies to configure policy enforcement.
Diff
Diff compares the synthesized CloudFormation templates with the deployed CloudFormation stacks and reports the changes that will be applied. The output includes resources that will be:
Added
Modified
Removed
It also highlights changes to IAM policies and security groups.
When Diff reports a resource replacement, the existing resource is destroyed before the new one is created. For stateful resources such as RDS instances or S3 buckets, review replacement notices before you approve a deploy.
Deploy
Deploy applies the infrastructure changes identified during the Diff step to provision or update your infrastructure. After the deployment completes, Harness records the deployment status and activity history for each stack in the workspace.
By default, deploy runs against all stacks. To deploy specific stacks, set PLUGIN_AWSCDK_STACKS to a comma-separated list of logical stack IDs, for example S3Stack,SqsStack.
Destroy
Destroy runs cdk destroy and deletes the CloudFormation stacks and AWS resources managed by the workspace, and removes the associated resources from the workspace resource mapping. The workspace itself is not deleted.
Use this step to clean up temporary or ephemeral environments.
By default, destroy runs against all stacks. To destroy specific stacks, set PLUGIN_AWSCDK_STACKS to a comma-separated list of logical stack IDs, for example S3Stack,SqsStack.
If you delete a stack from app.py (or your language equivalent), CloudFormation no longer manages it through the workspace, but the stack and its resources stay live in AWS. To delete the stack, run a Destroy operation that targets it or delete it from the AWS CloudFormation console.
Drift
Drift runs a drift detection operation that compares your deployed stacks against your CDK definition, using the CloudFormation drift detection API. Add Drift as a pipeline step or run it in a dedicated pipeline.
Drift detection for CDK is on-demand. A change made directly in AWS does not appear as drift automatically. Run the drift step to detect it, then run deploy again to reconcile the stack.
Go to Drift detection to review where drift is reported and how to resolve it.
Approvals
Use the IaCM Approval step to gate a deployment with a human review of the diff and OPA results. Go to Approval step to add one.
The CDK step Command dropdown may list an approval command. It is not operational (it fails with an invalid enum value) and it is being removed. Use the IaCM Approval step instead.
Troubleshooting
Related concepts
Go to Set up the AWS CDK provisioner to create the workspace and connector that these steps run against.
Go to OPA Policies to configure policy enforcement on synthesized CloudFormation templates.
Go to Approval step to gate a deployment on a human review of the diff output.
Go to Drift detection to review where drift results are reported and how to resolve them.
Last updated
Was this helpful?