Open mihok opened 1 year ago
Hi @mihok đ
As you're using account.id
in the key, Terraform should be able to automatically figure out the dependency between those two resources (you don't need to specify the dependency).
That said, if you would need to define the dependency, usually you would pass the whole resource into the dependsOn
property: key.dependsOn = [account]
(like done in HCL)
Thanks for looking at this @ansgarm, I reran the codebase with the instructions you have given me but Typescript suggests the value for dependsOn must be an array of strings, which is why I created this bug
Ah, got it. That's something we should check then đ¤ I came up with this because of this example which passes the resource construct: https://github.com/hashicorp/terraform-cdk/blob/217b7398fcc470d618f16f1095c3a88f69d6baeb/examples/typescript/google/main.ts#L46 (we run examples in CI, so it should fail if TypeScript does not like that)
Okay, there seems to be an inconsistency between dependencies passed via the initial config (like in the example I posted) and setting the property later on.
This extra bit happens if dependsOn
is defined in the config:
https://github.com/hashicorp/terraform-cdk/blob/217b7398fcc470d618f16f1095c3a88f69d6baeb/packages/cdktf/lib/terraform-resource.ts#L95-L99
So, the proper way in your case would be to call:
import { dependable } from "cdktf";
// ...
key.dependsOn = [dependable(account)]
But I agree that this could use some more docs (at least inline docstrings on the dependsOn
property; ideally some section in our docs).
Ideally setting after would also work with passing the entire object rather than needing to turn into a string. Can certainly improve documentation either way, but not requiring extra steps when late setting seems preferable.
is dependable
something exposed in non-type script versions of the cdk?
Community Note
Description
Currently tokens are forced into strings, and
dependsOn
oraddOverride
resolves these down to templated strings, which are not allowed. Where a block of code such as this:Which results in the following error from terraform:
There needs to be a simple way for people to reference the object without templated strings.
Ideally, this might be as simple as having some kind of
toUntemplatedString
(ugly, not set on the name of the function/property)So the above code would look something along the lines of:
Which result in a cdk.tf.json:
Happy to do some of the implementation if it helps!