Trouble using terraform test (modules and multiple providers)

Hi!

I am trying to execute integration/end 2 end tests for my terraform setup. Only I’m really struggling getting it to work. The problem is with the network module, as im using an extra provider as alias, to get the peering done between vnets (using an extra service account for this).

Folder structure: (2 modules, one for network and one for recovery services vault, plus a root module.
image

The problem is mainly with the network module, the module looks like this:

main.tf (root module):
image

provider.tf (root module):

What I want to accomplish:

  • Actual deploying of every resource in the module, validated by assertions.

I’ve been trying alot of things, to much to take all screenshots off, but I will give a brief overview.

  • I tried creating tests files from within the modules itself, but that did not work. For recovery services vault module it worked fine, but for the network module it kept complaining about the second provider, even though explicitly defined.

  • I’m now trying to just fire a test from within the root module (and ideally this will test both the modules, and deploy them in azure). But when I run it it just hangs, and does not return. I tried putting on logging with TF_LOG but it outputs nothing.

image

Any ideas/skeleton testfiles in how to get this working would be highly appreciated!

Anyone has an idea on this?

Hi @tijnster, sorry for the delay here. I have some questions about your current setup.

but for the network module it kept complaining about the second provider, even though explicitly defined.

Where was the second provider explicitly defined? If you’re executing terraform test directly from your modules then the providers will have to be defined within the test file itself, and you need to make sure the aliases for the providers match up. Were you doing this and it was still complaining about the missing provider?

But when I run it it just hangs, and does not return

I can see that you have defined your providers directly within the main configuration file for this, so I would expect that to work. Is the output just completely empty? Or do you see it trying to start the setup run block, and then it hangs? This behaviour suggests to me that the provider configuration is incomplete or invalid - you need to make sure you have installed all the required credentials for the provider for the test command to work. How do you execute your normal plan and apply runs? Are they working for you in the same environment that the test function is not? You should be careful with this, as the test command may create real infrastructure so it’s worth creating a separate cloud account to execute your tests within separate from your production account.

Sorry, I can’t see exactly what the problem is yet. Hopefully, we’ll be able to get to the bottom of it!