From e5c526308231b98dd8add1f8aa582c9f1820dd40 Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Fri, 19 Nov 2021 10:34:40 +0100 Subject: [PATCH 1/3] add docs entry for module.calls --- docs/commands.md | 41 +++++++++++++++++++ .../handlers/command/module_calls.go | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/commands.md b/docs/commands.md index 44e53f9a..9047342f 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -102,4 +102,45 @@ can be used to hint the user e.g. where to run `init` or `validate` from. } ``` +### `module.calls` + +List of module which are called from the current module. + +**Arguments:** + + - `uri` - URI of the directory of the module in question, e.g. `file:///path/to/network` + +**Outputs:** + + - `v` - describes version of the format; Will be used in the future to communicate format changes. + - `module_calls` - array of modules which are called from the module in question + - `name` - a unique identifier for this particular module + - `source_addr` - the source address given for this module in configuration + - `version` - the exact version of the module + - `source_type` - source of the Terraform module, e.g. github or tfregistry + - `docs_link` - a link to the module documentation; if available + - `dependent_modules` - array of dependent modules with the same structure as `module_calls` + +```json +{ + "v": 0, + "module_calls": [ + { + "name": "child", + "source_addr": "./child", + "source_type": "local", + "dependent_modules": [] + }, + { + "name": "vpc", + "source_addr": "terraform-aws-modules/vpc/aws", + "version": "3.11.0", + "source_type": "tfregistry", + "docs_link": "https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/3.11.0", + "dependent_modules": [] + } + ] +} +``` + ### `rootmodules` (DEPRECATED, use `module.callers` instead) diff --git a/internal/langserver/handlers/command/module_calls.go b/internal/langserver/handlers/command/module_calls.go index 9d7be602..92e94c69 100644 --- a/internal/langserver/handlers/command/module_calls.go +++ b/internal/langserver/handlers/command/module_calls.go @@ -87,7 +87,7 @@ func parseModuleRecords(records []datadir.ModuleRecord) []moduleCall { subModuleName := "" // determine if this module is nested in another module - // in the currecnt workspace by finding a period in the moduleName + // in the current workspace by finding a period in the moduleName // is it better to look at SourceAddr and compare? if strings.Contains(manifest.Key, ".") { v := strings.Split(manifest.Key, ".") From 37264a5a8c5b6b695cd1e57e98a1bd1b9965768e Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Fri, 19 Nov 2021 10:34:56 +0100 Subject: [PATCH 2/3] add docs entry for module.providers --- docs/commands.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/commands.md b/docs/commands.md index 9047342f..2ee83f30 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -143,4 +143,38 @@ List of module which are called from the current module. } ``` +### `module.providers` + +Provides information about the providers of the current module, including requirements and +installed version. + +**Arguments:** + + - `uri` - URI of the directory of the module in question, e.g. `file:///path/to/network` + +**Outputs:** + + - `v` - describes version of the format; Will be used in the future to communicate format changes. + - `provider_requirements` - map of provider FQN string to requirements object + - `display_name` - a user-friendly FQN string, simplified for readability + - `version_constraint` - a comma-separated list of version constraints + - `docs_link` - a link to the provider documentation; if available + - `installed_providers` - map of provider FQN string to installed version string; can be empty if none installed + +```json +{ + "v": 0, + "provider_requirements": { + "registry.terraform.io/hashicorp/aws": { + "display_name": "hashicorp/aws", + "version_constraint": "~> 3.64.0", + "docs_link": "https://registry.terraform.io/providers/hashicorp/aws/latest" + } + }, + "installed_providers": { + "registry.terraform.io/hashicorp/aws": "3.64.2" + } +} +``` + ### `rootmodules` (DEPRECATED, use `module.callers` instead) From 6dc9b06fc9ff2d0c16bbc7621626f0e60a8250ce Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Mon, 22 Nov 2021 10:55:32 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Radek Simko --- docs/commands.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 2ee83f30..67dc9bc3 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -104,7 +104,15 @@ can be used to hint the user e.g. where to run `init` or `validate` from. ### `module.calls` -List of module which are called from the current module. +List of modules called by the module under the given URI. + +Empty array may be returned when e.g. + - the URI doesn't represent a module + - the configuration is invalid + - modules are not installed + - there are no module calls + +The data is sourced from the local cache within `.terraform` and so it may not necessarily represent newly added module calls in the configuration until they're installed via `get` or `init`. **Arguments:** @@ -114,10 +122,10 @@ List of module which are called from the current module. - `v` - describes version of the format; Will be used in the future to communicate format changes. - `module_calls` - array of modules which are called from the module in question - - `name` - a unique identifier for this particular module - - `source_addr` - the source address given for this module in configuration - - `version` - the exact version of the module - - `source_type` - source of the Terraform module, e.g. github or tfregistry + - `name` - the reference name of this particular module (i.e. `network` from `module "network" { ...`) + - `source_addr` - the source address given for this module call (e.g. `terraform-aws-modules/eks/aws`) + - `version` - version constraint of the module call; applicable to modules hosted by the Terraform Registry (e.g. `~> 1.0` + - `source_type` - source of the Terraform module, e.g. `github` or `tfregistry` - `docs_link` - a link to the module documentation; if available - `dependent_modules` - array of dependent modules with the same structure as `module_calls` @@ -156,10 +164,10 @@ installed version. - `v` - describes version of the format; Will be used in the future to communicate format changes. - `provider_requirements` - map of provider FQN string to requirements object - - `display_name` - a user-friendly FQN string, simplified for readability - - `version_constraint` - a comma-separated list of version constraints + - `display_name` - a human-readable name of the provider (e.g. `hashicorp/aws`) + - `version_constraint` - a comma-separated list of version constraints (e.g. `>= 1.0, < 1.2`) - `docs_link` - a link to the provider documentation; if available - - `installed_providers` - map of provider FQN string to installed version string; can be empty if none installed + - `installed_providers` - map where _key_ is the provider FQN and _value_ is the installed version of the provider; can be empty if none are installed ```json {