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

Wrong links for non-official providers #116

Open
kristoflemmens opened this issue Dec 17, 2024 · 3 comments
Open

Wrong links for non-official providers #116

kristoflemmens opened this issue Dec 17, 2024 · 3 comments

Comments

@kristoflemmens
Copy link

Hi,

Since you closed the previous one, I need to create a new issue.

As I commented in #94, I did some extra tests. When I disable the extension I don't have any documentation links. I recreated your test with the following code:

terraform {
  required_version = "~> 1.9"

  required_providers {
    azapi = {
      source  = "Azure/azapi"
      version = "~> 1.15"
    }
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 4.0"
    }
  }
}

resource "azapi_resource_group" "rg" {
  name     = "example-resources"
  location = "East US"
}

resource "azurerm_resource_group" "rg" {
  name     = "example-resources"
  location = "East US"
}

And got the following extension output channel log:

[terraform-link-docs] LMR {"type":"module","range":[{"line":5,"character":17},{"line":5,"character":28}],"moduleSource":"Azure/azapi"}
[terraform-link-docs] LMR {"type":"module","range":[{"line":9,"character":17},{"line":9,"character":34}],"moduleSource":"hashicorp/azurerm"}
[terraform-link-docs] LMR {"type":"resource","range":[{"line":15,"character":10},{"line":15,"character":30}],"dataOrResource":"resource","resourceType":"azapi_resource_group"}
[terraform-link-docs] LMR {"type":"resource","range":[{"line":20,"character":10},{"line":20,"character":32}],"dataOrResource":"resource","resourceType":"azurerm_resource_group"}
[terraform-link-docs] resource link https://www.terraform.io/docs/providers/azapi/r/resource_group
[terraform-link-docs] resource link https://www.terraform.io/docs/providers/azurerm/r/resource_group
@mattwillsher
Copy link

I have the same issue.

terraform {
  required_version = "~> 1.10.0"

  required_providers {
    proxmox = {
      source  = "bpg/proxmox"
      version = "~> 0.69.0"
    }
  }
}

resource "proxmox_virtual_environment_download_file" "rocky9_qcow2" {
  node_name    = "proxmox-node"
  datastore_id = "local"
  url          = "https://download.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2"
  file_name    = "Rocky-9-GenericCloud.latest.x86_64.qcow2"
  content_type = "iso"
}
[terraform-link-docs] LMR {"type":"module","range":[{"line":5,"character":17},{"line":5,"character":28}],"moduleSource":"bpg/proxmox"}
[terraform-link-docs] LMR {"type":"resource","range":[{"line":18,"character":10},{"line":18,"character":58}],"dataOrResource":"resource","resourceType":"proxmox_virtual_environment_storage_download_url"}
[terraform-link-docs] resource link https://www.terraform.io/docs/providers/proxmox/r/virtual_environment_storage_download_url

The canonical URL for the resources docs is https://registry.terraform.io/providers/bpg/proxmox/latest/docs/resources/virtual_environment_download_file

@tdharris
Copy link
Owner

Wow, sorry! I just noticed that the "HashiCorp Terraform" vscode extension is overriding the popover links, so that's why I couldn't duplicate it originally. If I paste into a .tf file that is saved, the HashiCorp Terraform extension handles the link popover; however, if I paste into an open file that remains unsaved and select the Language Mode dropdown to pick Terraform, then my extension alone is handling the popover links for these resource and data types. Now I can duplicate, thank you for your persistence.

So now exploring.. The resource and data type resources have the provider name as a prefix, which used to work, though likely long ago in earlier versions of Terraform. Perhaps HashiCorp redirected links for a while to be backwards compatible. Anyways, for example:

data "aws_s3_bucket" "this" {} # "aws" provider
resource "proxmox_virtual_environment_download_file" "this" {} # "proxmox" provider

The problem I see now is that the documentation urls require the owner/ prefix of the provider. For example:

So while I can parse proxmox_virtual_environment_download_file into the following, I'm left wondering how I'd lookup the bgb part (the owner/ prefix to the provider):

  • provider: proxmox
  • resource: virtual_environment_download_file

I came up with something that naively builds a map of detected providers from a file by scanning for source lines within terraform.required_providers block, but that sadly only works for files where both the required_providers block and the related resources are defined together. Fairly often I see modules broken up into various files such as providers.tf, main.tf, dependencies.tf and outputs.tf so I feel this approach would be an insufficient solution..

I do know that HashiCorp has support for generating the resource and data popover documentation links (and they look prettier), so I thought I'd explore their extension support for this. I noticed their provided URL format is the same as my current one (without the owner/ part), so they are potentially handling that lookup part on their end, as the following URL gets redirected into this:

But if I try non-hashicorp resources, such as the one you provided proxmox_virtual_environment_download_file, their vscode extension also generates the "wrong" links:

So I'm not yet sure what to do next, as HashiCorp doesn't appear to have solved it either in their own extension for Partner Providers. Ideally they'd extend the existing link support they have for HashiCorp providers to Partner Providers as well. 🤔 Hmm, maybe I'm missing something?

@mattwillsher
Copy link

Thank you for your time and effort on this. I've yet to see a VSCode plugin handle this correctly. I wasn't aware the Hashicorp plugin had support for documentaton links, not that it helps here anyway.

FWIW, JetBrain's Terraform plugin does pull up the correct docs for Partner/Community Providers. I think it's closed source however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants