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

Completion of required_providers source and version from Terraform Registry #871

Open
11 tasks
radeksimko opened this issue Apr 12, 2022 · 0 comments
Open
11 tasks
Labels
enhancement New feature or request providers Functionality related to Terraform providers textDocument/completion

Comments

@radeksimko
Copy link
Member

radeksimko commented Apr 12, 2022

Background

Terraform has a rich ecosystem of providers published in the Terraform Registry.

In order to use a provider in Terraform 0.12+, the user has to declare it explicitly, e.g.

terraform {
  required_providers {
    hcs = {
      source = "hashicorp/hcs"
      version = "0.3.0"
    }
  }
}

We provide completion for most of the above, except for the values of source and version. As a result, unless the user is copy-pasting the provider address and/or version they can make a mistake which would be preventable with completion.

Expected User Experience

source

terraform {
  required_providers {
    hcs = {
      source = "# HERE #"
    }
  }
}

Upon typing >= 2 characters, the user will be provided with a list of providers from the Registry matching the typed name. e.g. if they type ad then the following list of 14 providers would come up:

https://registry.terraform.io/search/providers?q=ad

version

terraform {
  required_providers {
    hcs = {
      source = "hashicorp/aws"
      version = "# HERE #"
    }
  }
}

Upon completion, the user will be provided with a list of published versions of a given provider, e.g. in case of hashicorp/aws they will see the following:

  • 3.46.0
  • 3.45.0
  • 3.44.0
  • etc.

Proposal

hashicorp/hcl-lang

#868

hashicorp/terraform-schema

  • Set CompletionHooks for module source to CompleteRegistryProviderSources & CompleteLocalProviderSources
  • Update earlydecoder to obtain and track each requirement's *hcl.Range within module.Meta so that the completion hook for version has enough context
  • Set CompletionHooks for module version to CompleteRegistryProviderVersions

hashicorp/terraform-ls

  • Store updated module.Meta as above in state
    type ModuleMetadata struct {
    CoreRequirements version.Constraints
    Backend *tfmod.Backend
    ProviderReferences map[tfmod.ProviderRef]tfaddr.Provider
    ProviderRequirements tfmod.ProviderRequirements
    Variables map[string]tfmod.Variable
    Outputs map[string]tfmod.Output
    Filenames []string
    }
  • Expose ranges of module calls via Meta of PathContext to allow CompleteRegistryProviderVersions to establish which module source it should provide versions for
  • Introduce CompleteRegistryProviderSources completion hook to return addresses of modules from the Registry/Algolia
  • Introduce CompleteLocalProviderSources completion hook to return paths of all indexed modules (relative to where they're being called from)
  • Introduce CompleteRegistryProviderVersions completion hook to return versions of a given Registry module from the Registry
  • Register CompleteRegistryProviderSources, CompleteLocalProviderSources and CompleteRegistryProviderVersions to the DecoderContext
    dCtx := decoder.DecoderContext{
    UtmSource: "terraform-ls",
    UseUtmContent: true,
    }
  • Introduce ResolveRegistryProviderSource resolve hook for module source description
  • Introduce ResolveRegistryProviderVersion resolve hook for module version description

Implementation Notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request providers Functionality related to Terraform providers textDocument/completion
Projects
None yet
Development

No branches or pull requests

2 participants