3

Is there a way to get what’s exact version of the module being obtained or used ?

There are few places I am using the version like ~> 0.0.5 to consume the modules - would be good to know what’s used.

When I try to output the whole output block - it displays all the outputs published in the module (not the module’s attributes or metadata)

Naveen Vijay
  • 15,928
  • 7
  • 71
  • 92
  • 1
    Do you have any particular example of a module in question with sample usage? – Marcin Feb 05 '21 at 03:44
  • The answer for this question would depend on the way you consume the modules and where is their source. Is it local as part of your code (monorepo), or you are pulling the modules from a different repository. By looking and the provided information, namely ```~> 0.0.5``` it seems that you may be actually looking for providers which is different than modules. Please update your question with some example code snippets on what you have tried and what you want to achieve. – Nick Feb 05 '21 at 07:47
  • This is displayed during `terraform init`. – Matthew Schuchard Feb 05 '21 at 13:20

3 Answers3

9

In case anybody lands here, the best would be to look into the modules.json file which is held by Terraform in .terraform folder.

You can print its contents for example with jq (if you're using bash or similar):

cat .terraform/modules/modules.json | jq
  • To get only a specific key (e.g. version) of a specific module, use `cat .terraform/modules/modules.json | jq -r '.Modules[] | select(.Key == "aws.vpc") | .Version'` – Chiel Jun 19 '23 at 13:46
0

While running terraform init the list of used providers and theirs version is being displayed.

#> terraform init
Initializing modules...

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of hashicorp/azuread from the dependency lock file
- Reusing previous version of aztfmod/azurecaf from the dependency lock file
- Reusing previous version of azure/azapi from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Reusing previous version of hashicorp/null from the dependency lock file
- Reusing previous version of databricks/databricks from the dependency lock file
- Reusing previous version of hashicorp/azurerm from the dependency lock file
- Using previously-installed hashicorp/azuread v2.28.1
- Using previously-installed aztfmod/azurecaf v1.2.11
- Using previously-installed azure/azapi v0.5.0
- Using previously-installed hashicorp/random v3.4.3
- Using previously-installed hashicorp/null v3.1.1
- Using previously-installed databricks/databricks v0.6.1
- Using previously-installed hashicorp/azurerm v3.22.0

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
Will
  • 1,792
  • 2
  • 23
  • 44
0

Faced the same issue, didn't find any good way of doing it

Wrote a small utility tool in golang that shows the used version based on a module name input :

Project link

Usage :

❯ terraform-modules-used-version --module rds

Result is :

enter image description here

  • works both if your use terraform or terragrunt
  • you can search for a substring of the remove module name
Eyal Solomon
  • 470
  • 1
  • 6
  • 15