Terraform plan changes based on existence of depends_on in module

Hi @mimozell,

I’m not sure I follow exactly what’s going on here from your description, and so I can’t give a specific answer for your case, but I can give a general note:

depends_on gives Terraform less information about your intent than a direct expression reference would, because it states that anything done to the dependency object must happen before anything done to the one declaring the dependency. As a result, Terraform will often make more conservative plans (that is: plans which assume less and therefore propose to change more to ensure correct ordering) with depends_on.

Depending on an entire module call is particularly tricky because you tell Terraform that it should order every operation planned inside the module before the object declaring the dependency.

You can typically get more precise results if you avoid using depends_on and instead use expression references to imply dependencies wherever possible. In that case, Terraform can see specifically which value the reference derives from and thus avoid proposing changes if that particular value hasn’t changed, even if other parts of the upstream object have planned changes.

1 Like