CDK for Terraform (CDKTF) brings the expressive power of general-purpose programming languages to Terraform infrastructure definitions. Understanding the construct model, token resolution, synthesize cycle, and Iterators is key to building maintainable, scalable IaC with CDKTF.
0 / 5 completed
1 / 5
What is CDK for Terraform (CDKTF), and how does it relate to Terraform's HCL?
CDKTF is a framework that generates Terraform JSON configuration from code written in familiar programming languages. The output is standard Terraform — any provider, backend, or feature that works in HCL also works with CDKTF, and the actual infrastructure operations are still executed by the Terraform CLI.
2 / 5
In CDKTF, what does calling app.synth() do?
synth() is the compilation step: it traverses the construct tree of all stacks, resolves token values, and writes cdk.tf.json files to the output directory. No cloud API calls are made — it is a pure synthesis (code → JSON) operation.
3 / 5
CDKTF uses tokens for values not known until deployment. What happens when you reference one resource's attribute as another resource's input?
When you access an attribute of a CDKTF resource object (e.g., bucket.bucketArn), CDKTF returns a token — a placeholder that synthesises to a Terraform interpolation reference (${aws_s3_bucket.example.arn}) in the JSON. Terraform resolves the actual value during plan/apply.
4 / 5
What is a CDKTF Iterator used for?
A CDKTF Iterator wraps a dynamic collection and synthesises to Terraform's for_each. Unlike a JavaScript loop (which creates N separate resource blocks), an Iterator creates a single resource block with for_each, letting Terraform manage additions and removals from the collection at apply time without recreating unaffected resources.
5 / 5
You have two CDKTF Stacks — NetworkStack and AppStack. AppStack needs the VPC ID output from NetworkStack. How do you pass it?
CDKTF supports cross-stack references: referencing an output from another Stack automatically generates a terraform_remote_state data source in the dependent stack's synthesized JSON. This mirrors Terraform's native cross-state referencing, keeping stacks decoupled while sharing outputs.