terraform plan on cdktf output fails with "Incorrect attribute value type" and "string required"
Fixes the plan-time type error when a CDKTF-generated cdk.tf.json passes a whole module object where a string is required (e.g. name = ${module.resourceNaming.resource_group} referencing an 8-attribute object). Covers indexing into the output (resource_group["name"]) or using Fn lookup. Use when terraform plan on cdktf.out fails with Incorrect attribute value type. Not for synth-time JSII errors.
TL;DR
Index into the module output: change "name": "${module.resourceNaming.resource_group}" to "name": "${module.resourceNaming.resource_group[\"name\"]}" (or use Fn.lookup in CDKTF) so the attribute gets a string, not the whole object.
The error
│ Error: Incorrect attribute value type
│
│ on cdk.tf.json line 44, in resource.azurerm_resource_group.resource_group:
│ 44: "name": "${module.resourceNaming.resource_group}"
│ ├────────────────
│ │ module.resourceNaming.resource_group is object with 8 attributes
│
│ Inappropriate value for attribute "name": string required.Fix it
- In
cdk.tf.json, find the attribute the error names (nameon the resource group here). - In your CDKTF code, stop passing the whole module output token; index the key you need. TypeScript: `
${moduleOutput.getString("name")}-style access orFn.lookup(output, "name"). The generated JSON should read"${module.resourceNaming.resource_group[\"name\"]}"`. - Re-run
cdktf synthand confirm the attribute is now a string interpolation into the map key. - Run
terraform planincdktf.out/stacks/[stack]and confirm the type error is gone.
Expected result: plan succeeds with the attribute resolved to a string.
When to use this
terraform planoncdktf.outfails with "Incorrect attribute value type ... string required"- The generated JSON interpolates a whole module/object output where a scalar belongs
When NOT to use this
cdktf synthitself fails (fix the synth error first)- The type error is in hand-written HCL, not generated JSON
Root cause
Some CDKTF module bindings generate a token referencing the entire output object (a map) rather than the specific key. Terraform then sees an object where the schema requires a string. This commonly bites with naming/convention modules whose outputs are maps of many values.
Edge cases
Fn.lookupworks across languages and keeps the fix in code rather than edited JSON.- If the module output is a list, index with a number instead of a key.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.