I am writing to you about the subject matter at hand. Specifically, when I try to deploy two modules one of which has a dependency on the first module, it fails. I provide an example: the first module creates a cluster aks, the second module should go and perform tasks on the cluster nodes. The problem is that the ‘depends_on’ in this case does not work, because already when the ‘terraform plan’ command is executed, it is expected that the cluster already exists. The only solution I have found so far is to separate the execution of the two or more modules that give this problem. Do you know if there is another more efficient solution?
If you need to create some resources in order to plan other parts of your infrastructure, then you should usually be using multiple configurations for these separate parts. Think of it as creating the first layer of infrastructure, on top of which you will later deploy more infrastructure.
It is possible to use -target on the first plan to limit the actions to only the first module you want to apply, but that is not really any more efficient, and can cause other complications later on if you need to update multiple parts of the configuration.