Skip to content

Commit

Permalink
'terraform-docs#643 -adds support to show source in the requirements …
Browse files Browse the repository at this point in the history
…section'

Signed-off-by: Edgar R. Sandi <[email protected]>
  • Loading branch information
edgarsandi committed Jul 20, 2023
1 parent 577d2c8 commit 4213435
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions terraform/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ func loadRequirements(tfmodule *tfconfig.Module) []*Requirement {
for _, core := range tfmodule.RequiredCore {
requirements = append(requirements, &Requirement{
Name: "terraform",
Source: "hashicorp/terraform",
Version: types.String(core),
})
}
Expand All @@ -402,8 +403,16 @@ func loadRequirements(tfmodule *tfconfig.Module) []*Requirement {

for _, name := range names {
for _, version := range tfmodule.RequiredProviders[name].VersionConstraints {
var source string
if len(tfmodule.RequiredProviders[name].Source) > 0 {
source = tfmodule.RequiredProviders[name].Source
} else {
source = fmt.Sprintf("%s/%s", "hashicorp", name)
}

requirements = append(requirements, &Requirement{
Name: name,
Source: types.String(source),
Version: types.String(version),
})
}
Expand Down
1 change: 1 addition & 0 deletions terraform/requirement.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ import (
// Requirement represents a requirement for Terraform module.
type Requirement struct {
Name string `json:"name" toml:"name" xml:"name" yaml:"name"`
Source types.String `json:"source" toml:"source" xml:"source" yaml:"source"`
Version types.String `json:"version" toml:"version" xml:"version" yaml:"version"`
}

0 comments on commit 4213435

Please sign in to comment.