I have the following CDKTF file in python with the following code
MODULE_PATH = Token.as_string("${path.module}")
# some code
"MetadataFile": Fn.file(f"${MODULE_PATH}/{xml_asset.path}"),
When this gets synthesize, it will produce the following tf.json
"MetadataFile": "${file(\"$${path.module}/assets/xml_asset/E474FA1A5F88681658D71508D6557A90/metadata.xml\")}"
Now, when trying to deploy terraform, it will complain that the path
parameter for file
is invalid. The main issue is that there is an extra $
.
Using the following is a decent workaround
MODULE_PATH = Token.as_string("${path.module}")
# some code
"MetadataFile": f"${{file(\"{MODULE_PATH}/{xml_asset.path}\")}}",
It will produce the tf.json
"MetadataFile": "${file(\"${path.module}/assets/xml_asset/E474FA1A5F88681658D71508D6557A90/metadata.xml\")}"
which is correct and is able to be deployed.
I prefer the top method, it seems cleaner but I can’t make it work. Is there a way I can keep it clean and avoid writing terraform code inside my python?