How to check if module has completed tasK?

I have module to create k8s namespaces in like this:

module “kubesetup” {
for_each = toset(var.namespaces_tenants)
tenant = each.value
providers = { kubernetes = kubernetes.kubeconfig }
source = “./modules/kubesetup”

Then I have another module in which I can not use depends_on because it has provider configs inside that module. I tried to use this in module B call in namespaceok = module.kubesetup to create dependency between them, module B fails if kubesetup has not created all required namespaces in k8s first. Now when I run this setup I get error because of namespaces has not been created before module B executes? From logs I can see that kubesetup did start before module B but it did not finish. I assume that this is because of for_each loop, so first call to loop might be finished but not all iterations. So how can I make sure that all namespaces are created by module kubesetup before executing module B?

Hi @jouros

You can declare an output variable from module “kubesetup” as an input to the second module (you don’t need to actually use the input).

not_needed_variable =

That way a graph dependency is created and the second module is executed after the output variable from first module is resolved.

I have a very old example of that technique used to create an RDS subnet before the RDS instance is created:

In order to launch the RDS database the subnet needs to exist, we provide the name of the RDS subnet using the output ID of the RDS subnet as source, this way Terraform is forced to create the RDS subnet first in order to evaluate the output ID.

Let me know if if it works!

Hi @javierruizjimenez
Yes, that works, thanks!

1 Like