Tokens represent values that are unknown until Terraform (or OpenTofu) applies your configuration. For example, names of cloud resources are only assigned upon creation. Some attributes specified using CDK Terrain (CDKTN) may not directly map to the values required for Terraform configurations. You can use Tokens to cast these attributes to the correct Terraform language syntax.Documentation Index
Fetch the complete documentation index at: https://cdktn.io/docs/llms.txt
Use this file to discover all available pages before exploring further.
Use Tokens
You may need to use Tokens for:- Module outputs for boolean, string, lists, maps, and other complex types.
- Resource attributes (such as
id). - Terraform outputs based on resource attributes.
- Using Terraforms
nulltype.
Example
An EKS module requires a list of subnet ids in order to create a cluster. The VPC module outputs a list of subnets. To pass the subnet id list to the EKS module, you can usepublicSubnetsOutput to retrieve the list from the VPC. However, the subnets attribute
requires a list of strings. Use Token.asList(vpc.publicSubnetsOutput) to cast the interpolated module
output as a list of strings.
Token.asList(vpc.publicSubnetsOutput) to ["#{TOKEN[TOKEN.9]}"] and logRetention.numberValue to a big negative number like -123828381238238.
Later in synthesis, CDKTN will resolve the token to ${module.<module id>.public_subnets} and ${var.logRetentionInDays}.
Using Terraform’s null value
Some edge cases require passing the Terraform null value to for example an attribute of a resource.