terraform-docs / terraform-docs

Generate documentation from Terraform modules in various output formats
https://terraform-docs.io
MIT License
4.28k stars 553 forks source link

Some providers are shown, but others are not. And local execution does not match CI execution. #765

Open aamkye opened 7 months ago

aamkye commented 7 months ago

Describe the bug

GitHub Provider:

terraform {
  required_version = ">= 1.8.0, < 2.0.0"
  cloud {
    organization = "XXX"

    workspaces {
      name = "gh-terraform"
    }
  }

  required_providers {
    github = {
      source  = "integrations/github"
      version = "~> 6.0"
    }
  }
}

provider "github" {
  owner = "XXX"
  app_auth {}
}

Generates:

## Providers

No providers.

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.8.0, < 2.0.0 |
| <a name="requirement_github"></a> [github](#requirement\_github) | ~> 6.0 |

...

And now the fun part starts:

TFE Provider:

terraform {
  required_version = ">= 1.8.0, < 2.0.0"
  cloud {
    organization = "XXX"

    workspaces {
      name = "cloud-terraform"
    }
  }

  required_providers {
    tfe = {
      source  = "hashicorp/tfe"
      version = "~> 0.53"
    }
  }
}

provider "tfe" {
  organization = "XXX"
}

Generates:

## Providers

| Name | Version |
|------|---------|
| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | 0.53.0 |

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.8.0, < 2.0.0 |
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | ~> 0.53.0 |

I'd expect some consistency here 😅.

What is even more interesting, CI thinks differently than local and fails with:

...

All changes made by hooks:
diff --git a/cloud_terraform/readme.md b/cloud_terraform/readme.md
index 67aeb0d..fbac005 100644
--- a/cloud_terraform/readme.md
+++ b/cloud_terraform/readme.md
@@ -5,7 +5,7 @@

 | Name | Version |
 |------|---------|
-| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | 0.53.0 |
+| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | ~> 0.53.0 |

 ## Requirements

How can we reproduce it?

I think you could use the attached snippets.

+ config:

formatter: "markdown table" # this is required
version: "0.17"
# header-from: ""
# footer-from: ""
recursive:
  enabled: false
  path: ""
sections:
  hide: []
  show: []

content: |-
  {{ .Providers }}

  {{ .Requirements }}

  {{ .Resources }}

  {{ .Inputs }}

  {{ .Modules }}

  {{ .Outputs }}
output:
  file: readme.md
  mode: inject
  template: |-
    <!-- BEGIN_AUTOMATED_CLOUD_TF_DOCS_BLOCK -->
    {{ .Content }}
    <!-- END_AUTOMATED_CLOUD_TF_DOCS_BLOCK -->
output-values:
  enabled: false
  from: ""
sort:
  enabled: true
  by: name
settings:
  anchor: true
  color: true
  default: true
  description: true
  escape: true
  hide-empty: false
  html: true
  indent: 2
  lockfile: true
  read-comments: true
  required: true
  sensitive: true
  type: true

Environment information

> terraform-docs --version
terraform-docs version v0.17.0 darwin/arm64

+ version used in CI: https://github.com/terraform-docs/terraform-docs/releases/download/v0.17.0/terraform-docs-v0.17.0-linux-amd64.tar.gz

Nuru commented 5 months ago

Seeing this with v0.18.0 as well.

rquadling commented 4 months ago

I think https://github.com/terraform-docs/terraform-docs/issues/726 has a lot of mirroring with this issue.

At a sort of squinty guess, a provider needs to be used in the module that the README.md is being generated for. Sub-module usage of the provider doesn't seem to carry through to the root module.

I provide a ~hack~ solution.