Getting module repository address

I am trying to tag our AWS resources with address of the module which is used to provision them. I’d probably call this from inside the module to get something like (even better if it could be called from outside):
“tag_key”=<module_vcs_adress>
The address could be in form of /<repo_name>/.
It would be able if the module had access to its own source = “…”.

Any way how to do this?
Thanks!

Hi @jan-ludvik,

The source address of a module is not part of the runtime data available to expressions in your configuration, so the closest you could get to what you described here is to manually copy the source address into one of the input variable definitions inside the module block:

module "example" {
  source = "git::https://example.com/repository.git"

  module_address = "git::https://example.com/repository.git"
}

However, if your modules are each published at a specific single location that you use consistently everywhere then it could be more straightforward to teach each module about its own canonical source address, e.g. in a local value within the module’s source code, so that the caller doesn’t need to do anything special when calling it. Unless you routinely move your modules to different source addresses or publish the same module in multiple locations I’d expect that the module address would be pretty stable over time and thus not a significant maintenence burden, though of course I can’t see the details of your system so that assumption won’t necessarily apply in your case.

Hi @apparentlymart, thank you. I was considering copy pasting the address but I was hoping there is something like path.root for the module which would give me module source. Our module addresses don’t change that often but I thought it would be nice to have this automatic.
I will look into doing this with the approach you described.