Different ways of Dependency - dependsOn addDependency et al

Hi there.

I’m trying to get my head around different ways of specifying dependencies:

  • addDependency(…)
  • dependencies.push(…)
  • dependsOn(…)
  • dependables array

Like so:




and using dependables array like below

export class myResourceGroup extends Construct {

readonly myStorageAccount: StorageAccount;
readonly keyVault: KeyVault;
readonly dependables: ITerraformDependable;

constructor(…) {
this.myStorageAccount = new StorageAccount(…);
this.dependables = [this.myStorageAccount];

this.keyVault = new KeyVault(…);

I’m a bit new to the cdktf.
Question 1: what happens if I do not specify these dependencies, what would happen.
Question 2: And in the last case, how does cdktf know to use the dependables array as the dependency chain…
Question 3: I’ve noticed that sometimes we can get an error at synth if the dependables array is not populated… wherein myResourceGroup.keyVault would not be available if I did not push keyVault to dependables array. Why is that ?

Hi @hashipk :wave:

In most cases you don’t have to specify dependencies as the CDKTF and Terraform will figure those out for you.
CDKTF will detect cross stack references (if you pass a reference from one stack to another) and ensure that the two stacks are then deployed in the correct order.
Terraform will detect dependencies between resources and deploy those in the right order.