Proper use of modules in Terrafile


I have attempted to use a module in the Terrafile (as described in Terrafile - Terraspace). I stumped upon an issue with the azurerm_resource_group, which is declared as data in As far as I understand the Terraform docs, the data means that the resource group must have been created before and exist at the time of creating the stack with Terraspace. However, in our Terraspace app the resource group is created along all other resources, and so I get an error from the module that the resource group could not be found.
Because of that I cannot use the vendor module verbatim, but must copy its code to app/modules and get rid of the data “azurerm_resource_group” “this” declaration to be able to use the rest of the code.
Is there any solution that would allow me to use the vendor module code without any modification?
Any help will be much appreciated.


Not completely following. Let’s pretend terraspace is not involved at all here, but we’re using only pure terraform. In that case, believe would still need to have the existing azurerm_resource_group that the module you’re using expects. So in either case, you have to create the existing azurerm_resource_group ahead of time so the data source can reference it. Maybe missing something though.

I ended up using the vendor modules as a basis for our app modules. They need some customization anyway, as they don’t cover all available options. So at this time I find the Terrafile usefulness limited.
But generally I find Terraspace a great tool that fulfills our expectations and purpose.

I don’t really get your point too. If terraform said, resource group not found, that means you need to create it before creating a resource which depends on that resource group.
You have ‘depend_on’ on terraform if you need to be more explicit regarding the dependency.
Terrafile is very useful as you can centralize your git repo tf modules with versioning, tag, branch mechanism.

If your Terraspace project creates the resource group, then you can get the resource group id by putting it on the output of that module, so you don’t need to use data to retrieve it.

So we are missing a bunch of details on your case to understand your issue, IMO.
Put some code sample but I have never faced an issue like this with the Terrafile / vendor mechanism