hashicorp / terraform-plugin-docs

Generate and validate Terraform plugin/provider documentation.
Mozilla Public License 2.0
224 stars 68 forks source link

Unable to generate correct docs when one resource has same name as provider #419

Open alexhung opened 15 hours ago

alexhung commented 15 hours ago

Terraform CLI and terraform-plugin-docs Versions

Terraform v1.9.5
on darwin_amd64
+ provider registry.terraform.io/jfrog/project v1.9.1
tfplugindocs Version dev // v0.20.0 in go.mod

Provider Code

terraform {
  required_providers {
    project = {
      source  = "jfrog/project"
      version = "1.9.0"
    }
  }
}

resource "project" "myproject" {
  key = "myproj"
  display_name = "My Project"
  description  = "My Project"
  admin_privileges {
    manage_members   = true
    manage_resources = true
    index_resources  = true
  }
  max_storage_in_gibibytes   = 10
  block_deployments_on_limit = false
  email_notification         = true
}

Expected Behavior

Able to generate correct doc files for all other resources when one resource has same name as the provider. In our case, the provider name is project and one of the resource name is also project.

Actual Behavior

When tfplugindocs generate is executed, all the resource docs are replaced by content from resource project doc.

Steps to Reproduce

  1. tfplugindocs generate. That's all required.

How much impact is this issue causing?

High

Logs

https://gist.github.com/alexhung/da5c294048169cef6cd73f026804bdb8

Additional Information

After generating doc, all resource doc files are modified even though none should be updated.

alexh@alexh-mac terraform-provider-project % git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   docs/resources/environment.md
    modified:   docs/resources/group.md
    modified:   docs/resources/project.md
    modified:   docs/resources/repository.md
    modified:   docs/resources/role.md
    modified:   docs/resources/share_repository.md
    modified:   docs/resources/share_repository_with_all.md
    modified:   docs/resources/user.md

no changes added to commit (use "git add" and/or "git commit -a")

Using --provider-name arg has no effect.

Code of Conduct

alexhung commented 15 hours ago

When I run tfplugindocs validate --provider-name project, it fails with the following:

exporting schema from Terraform
compiling provider "project"
using Terraform CLI binary from PATH if available, otherwise downloading latest Terraform CLI binary
running terraform init
getting provider schema
2024/11/13 14:08:43 [DEBUG] Found documentation files [docs/guides/repositories_in_project.md docs/index.md docs/resources/environment.md docs/resources/group.md docs/resources/project.md docs/resources/repository.md docs/resources/role.md docs/resources/share_repository.md docs/resources/share_repository_with_all.md docs/resources/user.md]
running mixed directories check
2024/11/13 14:08:43 [DEBUG] Found directory: docs/guides
2024/11/13 14:08:43 [DEBUG] Found directory: docs
2024/11/13 14:08:43 [DEBUG] Found directory: docs/resources
2024/11/13 14:08:43 [DEBUG] Found directory: docs/resources
2024/11/13 14:08:43 [DEBUG] Found directory: docs/resources
2024/11/13 14:08:43 [DEBUG] Found directory: docs/resources
2024/11/13 14:08:43 [DEBUG] Found directory: docs/resources
2024/11/13 14:08:43 [DEBUG] Found directory: docs/resources
2024/11/13 14:08:43 [DEBUG] Found directory: docs/resources
2024/11/13 14:08:43 [DEBUG] Found directory: docs/resources
running number of files check
2024/11/13 14:08:43 [TRACE] Found 1 documentation files in directory: docs/guides
2024/11/13 14:08:43 [TRACE] Found 8 documentation files in directory: docs/resources
2024/11/13 14:08:43 [DEBUG] Found 9 documentation files with limit of 2000
detected static docs directory, running checks
running invalid directories check on docs/guides
running file checks on docs/guides/repositories_in_project.md
2024/11/13 14:08:43 [DEBUG] Checking file: /Users/alexh/Projects/terraform-provider-project/docs/guides/repositories_in_project.md
2024/11/13 14:08:43 [DEBUG] File /Users/alexh/Projects/terraform-provider-project/docs/guides/repositories_in_project.md size: 2447 (limit: 500000)
running file checks on docs/index.md
2024/11/13 14:08:43 [DEBUG] Checking file: /Users/alexh/Projects/terraform-provider-project/docs/index.md
2024/11/13 14:08:43 [DEBUG] File /Users/alexh/Projects/terraform-provider-project/docs/index.md size: 9837 (limit: 500000)
running invalid directories check on docs/resources
running file checks on docs/resources/environment.md
2024/11/13 14:08:43 [DEBUG] Checking file: /Users/alexh/Projects/terraform-provider-project/docs/resources/environment.md
2024/11/13 14:08:43 [DEBUG] File /Users/alexh/Projects/terraform-provider-project/docs/resources/environment.md size: 1200 (limit: 500000)
running file checks on docs/resources/group.md
2024/11/13 14:08:43 [DEBUG] Checking file: /Users/alexh/Projects/terraform-provider-project/docs/resources/group.md
2024/11/13 14:08:43 [DEBUG] File /Users/alexh/Projects/terraform-provider-project/docs/resources/group.md size: 1441 (limit: 500000)
running file checks on docs/resources/project.md
2024/11/13 14:08:43 [DEBUG] Checking file: /Users/alexh/Projects/terraform-provider-project/docs/resources/project.md
2024/11/13 14:08:43 [DEBUG] File /Users/alexh/Projects/terraform-provider-project/docs/resources/project.md size: 7627 (limit: 500000)
running file checks on docs/resources/repository.md
2024/11/13 14:08:43 [DEBUG] Checking file: /Users/alexh/Projects/terraform-provider-project/docs/resources/repository.md
2024/11/13 14:08:43 [DEBUG] File /Users/alexh/Projects/terraform-provider-project/docs/resources/repository.md size: 1128 (limit: 500000)
running file checks on docs/resources/role.md
2024/11/13 14:08:43 [DEBUG] Checking file: /Users/alexh/Projects/terraform-provider-project/docs/resources/role.md
2024/11/13 14:08:43 [DEBUG] File /Users/alexh/Projects/terraform-provider-project/docs/resources/role.md size: 2556 (limit: 500000)
running file checks on docs/resources/share_repository.md
2024/11/13 14:08:43 [DEBUG] Checking file: /Users/alexh/Projects/terraform-provider-project/docs/resources/share_repository.md
2024/11/13 14:08:43 [DEBUG] File /Users/alexh/Projects/terraform-provider-project/docs/resources/share_repository.md size: 1609 (limit: 500000)
running file checks on docs/resources/share_repository_with_all.md
2024/11/13 14:08:43 [DEBUG] Checking file: /Users/alexh/Projects/terraform-provider-project/docs/resources/share_repository_with_all.md
2024/11/13 14:08:43 [DEBUG] File /Users/alexh/Projects/terraform-provider-project/docs/resources/share_repository_with_all.md size: 1494 (limit: 500000)
running file checks on docs/resources/user.md
2024/11/13 14:08:43 [DEBUG] Checking file: /Users/alexh/Projects/terraform-provider-project/docs/resources/user.md
2024/11/13 14:08:43 [DEBUG] File /Users/alexh/Projects/terraform-provider-project/docs/resources/user.md size: 1676 (limit: 500000)
running file mismatch check
2024/11/13 14:08:43 [DEBUG] Found file environment.md
2024/11/13 14:08:43 [DEBUG] Found file group.md
2024/11/13 14:08:43 [DEBUG] Found file project.md
2024/11/13 14:08:43 [DEBUG] Found extraneous file project.md
2024/11/13 14:08:43 [DEBUG] Found file repository.md
2024/11/13 14:08:43 [DEBUG] Found file role.md
2024/11/13 14:08:43 [DEBUG] Found file share_repository.md
2024/11/13 14:08:43 [DEBUG] Found file share_repository_with_all.md
2024/11/13 14:08:43 [DEBUG] Found file user.md
2024/11/13 14:08:43 [DEBUG] Found resource project
2024/11/13 14:08:43 [DEBUG] Missing file for resource project
2024/11/13 14:08:43 [DEBUG] Found resource project_environment
2024/11/13 14:08:43 [DEBUG] Found resource project_group
2024/11/13 14:08:43 [DEBUG] Found resource project_repository
2024/11/13 14:08:43 [DEBUG] Found resource project_role
2024/11/13 14:08:43 [DEBUG] Found resource project_share_repository
2024/11/13 14:08:43 [DEBUG] Found resource project_share_repository_with_all
2024/11/13 14:08:43 [DEBUG] Found resource project_user
Error executing command: validation errors found:
matching resource for documentation file (project.md) not found, file is extraneous or incorrectly named
missing documentation file for resource: project