Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize inputs and outputs of uninitialized remote (Terraform Registry) modules #599

Closed
2 of 9 tasks
radeksimko opened this issue Aug 2, 2021 · 1 comment · Fixed by #924
Closed
2 of 9 tasks
Assignees
Labels
enhancement New feature or request modules Functionality related to the module block and modules generally textDocument/completion textDocument/definition textDocument/hover textDocument/references textDocument/semanticTokens Semantic syntax highlighting

Comments

@radeksimko
Copy link
Member

radeksimko commented Aug 2, 2021

Use-cases

Users may expect completion, hover, go to definition etc. to work automatically for a module block calling any publicly available module they write in their configuration, straight away, e.g.

module "eks" {
  source  = "terraform-aws-modules/eks/aws"
  version = "17.1.0"
}

Attempted Solutions / Workarounds

terraform get

Proposal

Pre-requisites

hashicorp/terraform-ls

  • Introduce new job GetModuleMetadataFromRegistry (alongside existing one such as LoadModuleMetadata) which will talk to the Registry API and cache responses keyed off the source address & version of a Registry module in memdb
  • Ensure GetModuleMetadataFromRegistry is scheduled from didOpen and didChange and depends on LoadModuleMetadata (as that job provides module call metadata)
  • state: Change ModuleStore.ModuleMeta(modPath string) to ModuleStore.InstalledModuleMeta(modPath string)
  • state: Implement ModuleStore.DeclaredModuleMeta(modCall tfmod.DeclaredModuleCall) which pulls out any previously cached Registry module metadata from memdb
func GetModuleMetadataFromRegistry(ctx context.Context, modStore *state.ModuleStore) error {
  // TODO: loop over module calls
  // TODO: check if any source address is Registry address
  // TODO: check if that address was already cached
  // TODO: if not, cache it
}

hashicorp/terraform-schema

  • schema: Introduce DeclaredModuleMeta(modCall tfmod.DeclaredModuleCall) (*tfmod.RemoteModuleMeta, error)
  • schema: Use DeclaredModuleMeta() within SchemaMerger
  • schema: For clarity, turn ModuleMeta(path string) into InstalledModuleMeta(path string) in ModuleReader interface

Implementation Notes

  • https://pkg.go.dev/github.com/hashicorp/terraform-registry-address is available for parsing and representing registry-based module addresses
  • Lookup of required module inputs can be done via Registry API v1
    • https://registry.terraform.io/v1/modules/{FULL_NAME}
    • e.g. curl 'https://registry.terraform.io/v1/modules/terraform-aws-modules/vpc/aws' | jq '.root.inputs[] | select(.required == true)'
@radeksimko radeksimko added the modules Functionality related to the module block and modules generally label Aug 5, 2021
@radeksimko radeksimko added the textDocument/semanticTokens Semantic syntax highlighting label Apr 25, 2022
@jpogran jpogran self-assigned this May 16, 2022
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request modules Functionality related to the module block and modules generally textDocument/completion textDocument/definition textDocument/hover textDocument/references textDocument/semanticTokens Semantic syntax highlighting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants