Skip to content

Commit

Permalink
Fixed broken links being generated by 'tfschema resource browse <reso…
Browse files Browse the repository at this point in the history
…urce>'
  • Loading branch information
bgavan committed Dec 18, 2021
1 parent 0ee145a commit b86491e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions command/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"github.com/mitchellh/cli"
)

const docBaseURL = "https://www.terraform.io/docs/providers/"
const docBaseURL = "https://registry.terraform.io/providers/hashicorp/"
const latestDocs = "/latest/docs"

// Meta are the meta-options that are available on all or most commands.
type Meta struct {
Expand All @@ -27,8 +28,8 @@ func detectProviderName(name string) (string, error) {

func buildProviderDocURL(providerName string) (string, error) {
// build a doc URL like this
// https://www.terraform.io/docs/providers/aws/index.html
url := docBaseURL + providerName + "/index.html"
// https://registry.terraform.io/providers/hashicorp/aws/latest/docs
url := docBaseURL + providerName + latestDocs
return url, nil
}

Expand All @@ -39,8 +40,8 @@ func buildResourceDocURL(resourceType string) (string, error) {
}

// build a doc URL like this
// https://www.terraform.io/docs/providers/aws/r/security_group.html
url := docBaseURL + s[0] + "/r/" + s[1] + ".html"
// https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group
url := docBaseURL + s[0] + latestDocs + "/resources/" + s[1]
return url, nil
}

Expand All @@ -51,8 +52,8 @@ func buildDataDocURL(dataSource string) (string, error) {
}

// build a doc URL like this
// https://www.terraform.io/docs/providers/aws/d/security_group.html
url := docBaseURL + s[0] + "/d/" + s[1] + ".html"
// https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group
url := docBaseURL + s[0] + latestDocs + "/data-sources/" + s[1]
return url, nil
}

Expand Down
6 changes: 3 additions & 3 deletions command/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestBuildProviderDocURL(t *testing.T) {
{
desc: "simple",
name: "aws",
want: "https://www.terraform.io/docs/providers/aws/index.html",
want: "https://registry.terraform.io/providers/hashicorp/aws/latest/docs",
ok: true,
},
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestBuildResourceDocURL(t *testing.T) {
{
desc: "simple",
name: "aws_security_group",
want: "https://www.terraform.io/docs/providers/aws/r/security_group.html",
want: "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group",
ok: true,
},
{
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestBuildDataDocURL(t *testing.T) {
{
desc: "simple",
name: "aws_security_group",
want: "https://www.terraform.io/docs/providers/aws/d/security_group.html",
want: "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group",
ok: true,
},
{
Expand Down

0 comments on commit b86491e

Please sign in to comment.