TerraformOutput class — the CDKTF equivalent of an HCL output block.

When to use outputs
Use Terraform outputs to:- Expose resource attributes for human inspection (printed after
cdktf deploy). - Share data between stacks (e.g., export a value from one stack to reference in another).
- Provide values to automation scripts or CI pipelines.
- Create resources.
- Store resource references in variables (so you can access attributes).
- Define
TerraformOutputinstances after resource creation.
Quick example: expose a README file’s content
Create a Terraform output that exposes thecontent attribute of a local file resource:
Define outputs after creating the resources they reference. Keep a reference to the resource (for example
readmeFile) so you can access attributes like readmeFile.content when constructing TerraformOutput.TerraformOutput quick reference
Example usage with optional properties:
Deploying and viewing outputs
When you runcdktf deploy, you’ll confirm the planned changes and, after apply completes, Terraform prints outputs. Example terminal session:
- Inspectable in the terminal,
- Used by other stacks,
- Consumed by automation or CI/CD pipelines.
References
- CDKTF documentation: CDK for Terraform (CDKTF)
- Terraform outputs: Terraform - Outputs
